Using python to issue command prompts
Question: I have been teaching myself python over the past few months and am finally
starting to do some useful things.

What I am trying to ultimately do is have a python script that acts as a
queue. That is, I would like to have a folder with a bunch of input files that
another program uses to run calculations (I am a theoretical physicist and do
many computational jobs a day).

The way I must do this now is put all of the input files on the box that has
the computational software. Then I have to convert the dos input files to unix
(dos2unix), following this I must copy the new input file to a file called
'INPUT'. Finally I run a command that starts the job.

All of these tasks are handled in a command prompt. My question is how to I
interface my program with the command prompt? Then, how can I monitor the
process (which I normally do via cpu usage and the TOP command), and have
python start the next job as soon as the last job finishes.

Sorry for rambling, I just do not know how to control a command prompt from a
script, and then have it automatically 'watch' the job.

Thanks


Answer: The [subprocess](http://docs.python.org/2/library/subprocess.html) module has
many tools for executing system commands in python.

    
    
    from subprocess import call
    call(["ls", "-l"])
    

[source](http://stackoverflow.com/a/89243/2502012)

call will wait for the command to finish and return its returncode, so you can
call another one afterwards knowing that the previous one has finished.

`os.system` is an older way to do it, but has fewer tools and isn't
recommended:

    
    
    import os
    os.system('"C:/Temp/a b c/Notepad.exe"')
    

**edit** FvD left a comment explaning how to "watch" the process below

