Executing shell command from python
Question: I am trying to compile a set of lines and execute them and append the output
to text file. Instead of writing the same thing, I used a python script to
compile and execute in background.

    
    
    import subprocess
    subprocess.call(["ifort","-openmp","mod1.f90","mod2.f90","pgm.f90","-o","op.o"])
    subprocess.call(["nohup","./op.o",">","myout.txt","&"])
    

The program `pgm.f90` is getting compliled using the ifort compiler, but the
ouput is not getting appended to `myout.txt`. Instead it is appending output
to `nohup.out` and the program is **not** running in the background even after
specifying `"&"` in the python script.

What obvious error have I made here?

Thanks in advance


Answer: You can call a subprocess as if you were in the shell by using `Popen()` with
the argument `shell=True`:

    
    
    subprocess.Popen("nohup ./op.o > myout.txt &", shell=True)
    

