简体   繁体   中英

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!!!

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM