在python脚本中捕获shell脚本响应代码

2024-06-29 00:52:05 发布

您现在位置:Python中文网/ 问答频道 /正文

这是我的python脚本

import subprocess

result = subprocess.Popen('./test.sh', stdin=subprocess.PIPE, stderr=subprocess.PIPE,         stdout=subprocess.PIPE, shell=True)
output, err = result.communicate()
print output

这是我的shell脚本

testFn(){
exit 1;
}

testFn "hello"

在执行python脚本之后,我需要打印1,但是我什么也看不到。我做错什么了?你知道吗


Tags: testimport脚本trueoutputshstderrstdin