0

I am trying to use Python subprocess to call a command recursively. To summarize what I am doing, command "info" has multiple sub-commands that does various functions, i.e.

info list 
info copy
info share
info run-script -f <script_file to run>

The problem is the info run-script command. On a command terminal, if someone input

info run-script -f script.sc

Content of script.sc:

info list
info copy

Then in the code I open a subprocess and call info: subprocess(['info', 'list']), when I do this, the process appeared to be lost and never came back. Is it because there is already an instance of info running? Has anyone run into this and have a solution or explanation?

Thanks, Matt

Ray
  • 2,472
  • 18
  • 22
user2719735
  • 97
  • 2
  • 10
  • What do you mean by "the process appeared to be lost and never came back"? – jayelm Feb 05 '14 at 01:54
  • What do you mean "lost and never came back"? Do you not see output but expect to? Or does the program run forever? Did your computer raise an Amber alert? – SethMMorton Feb 05 '14 at 01:54
  • You can use multiprocessing… Take a look at this question: [1]: http://stackoverflow.com/questions/15840550/running-script-multiple-times-simultaniously-in-python-2-7 – Shahram Feb 05 '14 at 02:26
  • There are many ways to solve this issue 1) see if your commands return result in stderr/stdout... 2) if your command goes to forever, try executing the command in background to see whats going on 3) is info located to right binary? 4) i would put timeout for the process by signaling 5) periodically print result of your command 6) use multiprocessing to solve – chk Feb 05 '14 at 03:18
  • As long as the "script file" can only contain more commands for this program, is there a reason you can't parse it and run them individually inside the same process? If it can contain commands not for your program (like a full on bash script or something), I think your program is probably trying to do too much. – jpmc26 Feb 05 '14 at 03:41
  • "lost and never came back" means that the process never returns. When I tried to do ps -ef | grep info, I can see 2 processes running. If I kill the child process, then the system exits cleanly. – user2719735 Feb 05 '14 at 20:10
  • "lost and never came back" means that the child process never returns. When I tried to do ps -ef | grep info, I can see 2 info processes running. If I kill the child process, then the system exits cleanly. Initially I tried to print the return result to sterr/stdout and have a timeout and the child process hangs and never came back. subproc = subprocess.Popen(['info', 'list'], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) (out, err) = subproc.communicate(). Then I made stdout and stderr set to None, with this the system exits cleanly. However I need to collect the output. – user2719735 Feb 05 '14 at 20:22

0 Answers0