2

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

sag
  • 445
  • 1
  • 5
  • 6
  • See [this](http://stackoverflow.com/questions/507347/hide-command-window-of-bat-file-that-executes-another-exe-file) question. – compie Jul 14 '10 at 06:33

2 Answers2

1

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
  • 48,066
  • 12
  • 84
  • 109
  • 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 Jul 14 '10 at 07:23
  • thankyou so much., i have used call() and the problem is solved... u rockz man sag – sag Jul 14 '10 at 07:31
  • For completeness' sake I've added a note regarding `check_call`. – Philipp Jul 14 '10 at 07:35
0

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
  • 112,946
  • 110
  • 377
  • 526