Differences between revisions 1 and 2
Revision 1 as of 2007-04-18 22:39:58
Size: 1412
Editor: GrantEdwards
Comment:
Revision 2 as of 2007-04-18 22:45:53
Size: 1629
Editor: GrantEdwards
Comment:
Deletions are marked like this. Additions are marked like this.
Line 19: Line 19:
anytime os.popen() is used with the CWD is a UNC path such as
{{{\\hostname\dirname\...}}} rather than a DOS style path such as
{{{G:dirname}}}. While this isn't specific to py2exe, the
problem is rarely encountered unless a program has been
distributed using
something like py2exe and is being
invo
ked by clicking on something on the network to which the
user has browsed.
anytime os.popen() is used with a current working directory
(
CWD) that is a UNC path such as {{{\\hostname\dirname\...}}}
rather than a DOS style path such as {{{G:dirname}}}. While
this isn't specific to py2exe, the problem is rarely
encountered unless a program has been distributed using
something like py2exe and is being executed by clicking on a
file or shortcut to which the user has browsed on the networ
k.
Line 30: Line 30:
The solution is to use subprocess.Popen() instead of
os.popen(). However, subprocess.Popen() has its own
Windows-related bug which requires working around.
See the Py2ExeSubprocessInteractions page for examples on
working around subprocess.Popen bugs that show up when using
py2exe.
The solution is to use subprocess.Popen() with shell=False
(which won't use cmd.exe)
instead of os.popen() (which does use
cmd.exe)
. However, subprocess.Popen() has its own
Windows-related bug which requires working around. See the
subprocess documentation at
http://docs.python.org/dev/lib/module-subprocess.html for
general usage and
Py2ExeSubprocessInteractions page for
examples on working around subprocess.Popen bugs that show up
when using
py2exe. 

os.popen

os.popen() doesn't work when the CWD is a UNC path like \\hostname\dirname\....

The call to os.popen() will appear to succeed, but subsequent calls to read/write the returned pipe will result in an IOError: invalid parameter exception.

This failure is not specific to py2exe as it will happen anytime os.popen() is used with a current working directory (CWD) that is a UNC path such as \\hostname\dirname\... rather than a DOS style path such as G:dirname. While this isn't specific to py2exe, the problem is rarely encountered unless a program has been distributed using something like py2exe and is being executed by clicking on a file or shortcut to which the user has browsed on the network.

The underlying problem is due to a "feature" in cmd.exe documented at http://support.microsoft.com/kb/156276/EN-US/

The solution is to use subprocess.Popen() with shell=False (which won't use cmd.exe) instead of os.popen() (which does use cmd.exe). However, subprocess.Popen() has its own Windows-related bug which requires working around. See the subprocess documentation at http://docs.python.org/dev/lib/module-subprocess.html for general usage and Py2ExeSubprocessInteractions page for examples on working around subprocess.Popen bugs that show up when using py2exe.

os.popen (last edited 2008-07-08 11:27:43 by localhost)