I'm using GNU/Linux and python 2.7.3, I'm new on it. I'm trying to execute a long installed system process like ffmpeg using the Popen() command to avoid blocking the main python process. I can't make it work.
My first attempt was to use threads, but it is a bit complicated, because the graphical interface doesn't work properly (and I suppose there has to be a better way)
Then I tried fork, but it is like killing flies with tanks.
Now I'm trying to use Popen, I saw a lot of references to its use in the internet, but I'm not running it properly I think. Maybe I'm misunderstanding the examples.
I've tried:
##command is ffmpeg like that works ok
p = subprocess.Popen(command, shell=True)
I've tried also:
p = subprocess.Popen(command,stdin=PIPE, shell=True)
Usually I get an error or a sequentcial behavior, the command ends and then the main program resumes. What am I missing?
The command part:
global vidSource
global srtSource
global done
size = "3"
font = "/usr/share/fonts/truetype/freefont/FreeSerif.ttf"
command = 'mencoder ' + '"' + vidSource + '"' + " -oac copy -ovc lavc -lavdopts threads=2 -sub " + "'" + srtSource + "'" + " -subcp -utf8 -font "+ '"'+ font+ '"' + " -subfont-text-scale " + size + " -o " + '"' + vidSource + '2'+'"'
Popenusesfork()(on linux) for creating new processes... If you didn't want to fork for some reason, Popen is not a viable solution.