[python-win32] Hidden CLI

Tim Golden tim.golden at viacom-outdoor.co.uk
Fri Sep 3 09:34:28 CEST 2004


| I have written a program that consists simply of three buttons (using
| wxPython). Clicking one of those buttons triggers an event where curl
| is executed and the information returned is stored into a file. The
| command is simply:
| 
| curl http://www.example.org?a=user^&b=pass -o setup.bat
| 
| I can run this command without any problem. However, the 'problem'
| that arises is that while curl is being run a Command Prompt appears.
| Since this app is for techno-phobes and can only imagine how much
| several windows opening and closing on their own would freak them out,
| I am trying to keep the user from seeing this window. I was wondering
| if there was a way to run the command without having it open a Command
| Prompt.

A good option is to use the popen command from the os
module, or one of the slightly more powerful alternatives
from the popen2 module. In essence, you'll be doing this:

f = os.popen ("curl http://www.example.org?a=user^&b=pass -o setup.bat")

The f is an open read-only file which contains the output from
the command. You can just throw it away if you're not bothered,
or you can parse the output for useful information.

Example:

<interpreter dump>
>>>
>>>
>>> import os
>>> f = os.popen ("dir c:\\")
>>> print "".join (f.readlines ())
 Volume in drive C has no label.
 Volume Serial Number is FC4F-7311

 Directory of c:\

28/10/2003  10:29       <DIR>          AM PC Fonts
10/09/2003  15:25       <DIR>          BACKUP
18/06/2004  10:32                  531 BARLOWJ_log.txt
21/06/2004  09:24                    0 cas.sql
28/10/2003  14:33                  529 CHRISF_log.txt
.
.
.
</interpreter dump>

HTH
Tim

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________


More information about the Python-win32 mailing list