I have a code executed the following way
$ python mycode.py param1 param2
It produces output using subprocess inside mycode.py
:
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
I have no problem getting the complete result using these commands:
$ python mycode.py > output.txt
$ python mycode.py >> output.txt
But when I do one of this, I get empty result in output.txt
:
$ nohup python mycode.py > output.txt &
$ nohup python mycode.py >> output.txt &
$ nohup python mycode.py >> output.txt 2>&1
What's the correct way to do it?
Update:
I fixed the problem. As pointed by CharlesDuffy the problem is in othercodes.py
.
In particular these lines:
# # 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)
Once I commented out the last 3 lines, mycode.py
then works fine.