1

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.

neversaint
  • 60,904
  • 137
  • 310
  • 477
  • What is it that "doesn't work"? How "incomplete" is it? – J. Chomel Sep 02 '16 at 09:11
  • 2
    Provide a fully complete reproducer. The contents of `othercode.py` (can potentially) matter -- if it checks for whether the process has a controlling TTY, for instance. Depending on that external code but not providing it (or, better, providing the smallest possible code you can test to produce the same behavior) means there's no guarantee anyone else can reproduce your problem. – Charles Duffy Sep 03 '16 at 01:26
  • @CharlesDuffy: You're right.`othercodes.py` is the problem. It produces error when I do nohup on it. This is external code not made by me. Is there any way I can wrap that code so that it can print result on nohup? – neversaint Sep 03 '16 at 01:33

0 Answers0