[python-win32] Hidden CLI
Bob Gailer
bgailer at alum.rpi.edu
Fri Sep 3 18:51:55 CEST 2004
At 10:21 AM 9/3/2004, Lewis Franklin wrote:
>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.
You can also use os.path.exists(filepath) which returns True if file exists
else False.
>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?
# From os help 6.1.2: "popen: Open a pipe to or from command. The return
value is an open
# file object connected to the pipe, which can be read or written depending
# on whether mode is 'r' (default) or 'w'. "
# if you do not assign the returned file object, popen opens and writes the
file, then the file is closed
# so do the following:
f = popen(process)
f.readlines() # returns lines written by process to std_out
Bob Gailer
bgailer at alum.rpi.edu
303 442 2625 home
720 938 2625 cell
More information about the Python-win32
mailing list