Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python Subprocess with Complex Command

This question stems from my lack of knowledge surrounding the structure of UNIX commands and the SUBPROCESS module, so please forgive my naivete in advance.

I have a command, that looks something like this

path/to/openmpi/mpirun -machinefile machine.file -np 256 /path/to/excecutable </dev/null &> output.out &

I know how the structure of MPIrun works, and I think my executable writes its data to stdout and I redirect it to a file called output.out. I have used this command in python scripts using os.sys(), but I would like to use subprocess so that when the executable finished running (in the background), the python script can resume doing 'things.'

I have no idea where to start, so if someone has any tips or can show me the proper way to format the subprocess command, I would be really grateful. All personal attempts at using subprocess result in epic failures.

Thanks!!!

like image 898
Michael R Avatar asked Sep 14 '25 19:09

Michael R


1 Answers

It's pretty straightforward.

from subprocess import call
call(["path/to/openmpi/mpirun", "-machinefile machine.file -np 256 /path/to/excecutable </dev/null &> output.out &"])

Generally, you'd provide the arguments to the command as a list, but I think this should work just as well. If not, break up each argument into a new element of the list.

This answer goes more into the limitations of this method.

like image 122
Jared Andrews Avatar answered Sep 16 '25 09:09

Jared Andrews