[Tutor] subprocess.Popen(..., cwd) and UNC paths

eryksun eryksun at gmail.com
Fri May 1 17:26:50 CEST 2015


On Fri, May 1, 2015 at 8:03 AM, Albert-Jan Roskam <fomcl at yahoo.com> wrote:
> I used a str for cmd because I found it more readable that way. I could do cmd.split().

Don't use cmd.split(). That just splits on whitespace without
respecting how the shell tokenizes the command. Use shlex.split(cmd)
instead.

> So os.getcwd() == os.path.dirname(os.path.abspath(__file__)) here?

No, a Python script could be started from any directory, while the RHS
there is specifically the directory of the script. In terms of a
crusty old cmd script we're talking about the difference between %cd%
and %~dp0 (where d=drive and p=path).


More information about the Tutor mailing list