[python-win32] Hidden CLI

Lewis Franklin lewis.franklin at gmail.com
Fri Sep 3 18:21:14 CEST 2004


Tim,

Thanks for your help. I tried popen and technically, it does work.
However, I need a way to make sure it was successful. Since the curl
creates a new file, I run the following code afterwards:

try:
    f = open('rsetup.bat', 'r')
    for line in f:
        a = line.find('set RSYNC_USER=')
        if a == 0:
            user = line[15:].strip()
            break
except:
    return 1

I continually get an error at level 1 (from the above return) because
the file cannot be opened. However, once I exit the program, the file
is there and has the proper information. It seems that Python moves on
after the pipe is opened instead of waiting for it to complete (which
I'm sure is a desired behavior). However, I need to make sure the pipe
was successful in (1) creating the file and (2) populating it with the
proper information. Is there any suggestions on how I can do this?

Lewis


On Fri, 3 Sep 2004 08:34:28 +0100 , Tim Golden
<tim.golden at viacom-outdoor.co.uk> wrote:
> | 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