views:

62

answers:

3

hi friends.,

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

A: 

See this question.

compie
A: 

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.

Matt Joiner
A: 

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.

Philipp
yes this is perfectly working but.,segwin.exe is returning 1 on success which causes to raise CalledProcessError by check_all(). what should i do now :(
sag
thankyou so much., i have used call() and the problem is solved...u rockz mansag
sag
For completeness' sake I've added a note regarding `check_call`.
Philipp