[Tutor] (Self resolved) os.spawn behavior issue

David Broadwell dbroadwell at mindspring.com
Fri Dec 10 19:58:12 CET 2004


Further note: widen the window, this has long strings in it ... and is
PURELY for edification.

To work around a problem between my ISP and my router, I have to make my
router RELogin the PPPoE every time the wan ip changes. Which is not hard,
it's a http string in a browser to log in, followed by a pause and a second
http string to make the magic internet return, and my DDNS client is very
good at telling when it ceases to work. While I am a relative code noob,
this with a sleep.py was hacked out in 30 minutes (after some testing).

But being a perfectionist, I want to do it entirely in python.
First with controlling the browser, than maybe later socket connections to
the router itself.

<psudocode>
import os,time
os.spawn(os.P_NOWAIT,browser,[logincommand])
time.sleep(20)
os.spawn(os.P_NOWAIT,browser,[relogcommand])
exit
</psudocode>

I have been hacking at getting os.spawnv to do what I want it to, with no
luck.

The 'want' is a simple one, open a browser (in this case IE) to a given URL.

Like;
YOUR PROMPT HERE> "C:/Program Files/Internet Explorer/Iexplore.exe"
http://www.yahoo.com
Which functions as expected.

Even os.system('"C:\Program Files\Internet Explorer\Iexplore.exe"
http://www.yahoo.com')
Works, but waits for the browser to close to return, and I need an immediate
return.

Here are some things I've tried ... Which to simplify for a tutor posting

# Yields: Just Opens IE Successfully As expected!
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
[])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
[])

# Yields: Invalid Argument - forward slash, full command string
# os.spawnv(os.P_NOWAIT,'"C:/Program Files/Internet Explorer/Iexplore.exe"
www.yahoo.com',[])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe
http://www.yahoo.com',[])
# os.spawnv(os.P_NOWAIT,'"C:/Program Files/Internet Explorer/Iexplore.exe"
http://www.yahoo.com',[])
# os.spawnv(os.P_NOWAIT,'"C:/Program Files/Internet Explorer/Iexplore.exe"
http:////www.yahoo.com',[])
# os.spawnv(os.P_NOWAIT,r'C:/Program Files/Internet Explorer/Iexplore.exe
http://www.yahoo.com',[])
# os.spawnv(os.P_NOWAIT,r'"C:/Program Files/Internet Explorer/Iexplore.exe"
http://www.yahoo.com',[])

# Yields: No such file or directory
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe
www.yahoo.com',[])

# Yields: Opens IE Successfully - Yet No ARG Passed to browser
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
['www.yahoo.com'])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
["www.yahoo.com"])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
['"www.yahoo.com"'])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
[r'www.yahoo.com'])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
[r"www.yahoo.com"])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
[r'"www.yahoo.com"'])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
['"http://www.yahoo.com"'])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
["http://www.yahoo.com"])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
['http://www.yahoo.com'])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
['"http:////www.yahoo.com"'])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
["http:////www.yahoo.com"])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
['http:////www.yahoo.com'])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
[r'"http://www.yahoo.com"'])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
[r"http://www.yahoo.com"])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
[r'http://www.yahoo.com'])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
['www.yahoo.com'])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
["www.yahoo.com"])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
['"www.yahoo.com"'])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
[r'www.yahoo.com'])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
[r"www.yahoo.com"])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
[r'"www.yahoo.com"'])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
['"http://www.yahoo.com"'])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
["http://www.yahoo.com"])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
['http://www.yahoo.com'])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
['"http:////www.yahoo.com"'])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
["http:////www.yahoo.com"])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
['http:////www.yahoo.com'])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
[r'"http://www.yahoo.com"'])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
[r"http://www.yahoo.com"])
# os.spawnv(os.P_NOWAIT,'C:/Program Files/Internet Explorer/Iexplore.exe',
[r'http://www.yahoo.com'])

The issue seems to be passing the [argument] to the program .. Even example
source I've found on the net has
Sorry about the widthspam, any suggestions?

--

AND as I always search after I've completely written my message, I found a
tip from Richard Chamberlain in July of 2000
http://mail.python.org/pipermail/tutor/2000-July/001759.html.

# Yields Browser with
'http://files/Internet%20Explorer/Iexplore.exe%20www.yahoo.com' string in
it.
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
["C:/Program Files/Internet Explorer/Iexplore.exe", 'www.yahoo.com'])
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
[r"C:/Program Files/Internet Explorer/Iexplore.exe", 'www.yahoo.com'])

# Yields Browser with 'http://explorer/Iexplore.exe%20www.yahoo.com'
# os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
["C:/Progra~1/Internet Explorer/Iexplore.exe", 'www.yahoo.com'])

# Finally! Yields browser with www.yahoo.com in it!!
os.spawnv(os.P_NOWAIT,"C:/Program Files/Internet Explorer/Iexplore.exe",
["C:/Progra~1/Intern~1/Iexplore.exe", 'www.yahoo.com'])

Man was this unpythonesque.

Why in the world doesn't the
http://www.python.org/doc/2.4/lib/os-process.html state that the program
name is required twice? Ok, the example DOES show it, but that is it ...
it's left unsaid.

Aside form that, that the list cannot handle Long File Names, does ~seem~ to
need to be addressed, I'm not the one to say that it is wrong as it is.

--

David Broadwell

OT: Fun with spellchecker in this message;
RELogin = Religion
PPPoE = Pope
IP = imp
psucodoce = pseudopodia
sleep.py = sloppy
os,time = costume



More information about the Tutor mailing list