我有一个代码按以下方式执行
$ python mycode.py param1 param2
它使用mycode.py
内的subprocess生成输出:
import subprocess
paramlist = ['othercodes.py','infilel.txt']
p = subprocess.Popen(paramlist,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
out, err = p.communicate()
# out is empty under nohup
print out
我可以使用以下命令获得完整的结果:
$ python mycode.py > output.txt
$ python mycode.py >> output.txt
但当我执行其中一个操作时,我在output.txt
中得到空结果:
$ nohup python mycode.py > output.txt &
$ nohup python mycode.py >> output.txt &
$ nohup python mycode.py >> output.txt 2>&1
正确的方法是什么?你知道吗
更新:
我解决了这个问题。正如CharlesDuffy所指出的,问题出在othercodes.py
。
尤其是这些线路:
# # If there's input ready, do something, else do something
# # else. Note timeout is zero so select won't block at all.
# if sys.stdin in select.select([sys.stdin], [], [], 0)[0]:
# infile = sys.stdin.readline().strip()
# args.append(infile)
一旦我注释掉最后3行,mycode.py
就可以了。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐