sag
sag

Reputation: 475

Stop invoking of new Shell/cmd prompt , python

i have a python script which should invoke a .exe file to get some result. That .exe file is invoking a new windows command prompt(shell) . i dont need any output from the .exe file.

i 'm using os.system('segwin.exe args') in my script where segwin is an executable.

now my question is : i need to stop invoking cmd prompt

kudos to all

sag

Upvotes: 2

Views: 525

Answers (2)

Philipp
Philipp

Reputation: 49842

Try this (untested):

import subprocess
CREATE_NO_WINDOW = 0x08000000
args = [...]
subprocess.check_call(["segwin.exe"] + args, creationflags=CREATE_NO_WINDOW)

Note that check_call checks the return code of the launched subprocess and raises an exception if it's nonzero. If you don't want that, use call instead.

In general, avoid os.system() and use the subprocess module whenever possible. os.system() always starts a shell, which is nonportable unnecessary on most cases.

Upvotes: 1

Matt Joiner
Matt Joiner

Reputation: 118600

This is actually specific to Windows. Windows has decided that segwin.exe is a console-based application (uses the Console subsystem from the Windows C interface).

I know how to invoke an prompt for apps that don't necessarily want one, but not the reverse, you could try using this, or this.

Upvotes: 0

Related Questions