2

I am trying to run a command using os or subproccess module in python. the command prompt window briefly flickers before terminating. Is there a way of eliminating that popping up of command prompt window..?

For example:

os.system("ffmpeg -i output.wav output.flac")

Is there a way I can run this in the background so that user may not notice this..?

I am running windows 7 with python 2.7.

3 Answers 3

1

The easiest thing would be to try to take advantage of the subproccess modules partial support for the STARTUPINFO structure. Something like this:

info = subprocess.STARTUP_INFO()
info.dwFlags = subprocess.STARTF_USESTDHANDLES | subprocess.STARTF_USESHOWWINDOW
info.wShowWindow = subprocess.SW_HIDE

process = subprocess.Popen("ffmpeg -i output.wav output.flac", startupinfo=info)
process.wait()
0

of coarse ... you even tagged it with the module you would use ...

subproccess.Popen("ffmpeg -i output.wav output.flac".split(),shell=True).communicate()

should do it ...

4
  • I think you mean shell=False.
    – dano
    Jul 26, 2014 at 19:38
  • shell=True will tell it to use the system environment ... so that you dont have to pass in things like env ... shell=False will likely break unless ffmpeg is in the same folder as the script or an absolute path is passed in Jul 26, 2014 at 20:20
  • You can't pass a list of arguments if you're using shell=True, it has to be a string. And when you use shell=False you still get the system environment, you're just not actually spawning a shell to execute the command. Also, OP is specifically looking to avoid a command prompt window briefly appearing when the command runs, which I imagine using shell=True would not prevent (don't have a Windows machine to verify this, though).
    – dano
    Jul 26, 2014 at 20:24
  • yeah it looks like you're right it doesn't need to pass shell is true on Windows... my bad Jul 26, 2014 at 20:48
0

def asyncRun(command): os.system(command)

t = Thread(target=asyncRun, args=('ping 127.0.0.1 -s 271',)) t.start()

works on windows 10 + EMET + 2.7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.