[python-win32] want to leave DOS console at any target dir

Paul Moore p.f.moore at gmail.com
Thu Nov 22 14:05:06 CET 2007


On 22/11/2007, Charlie <charlie at sallyandcharlie.com> wrote:
>  That launches a new DOS console at the desired directory location.
>
>  Pretty close to what I was hoping for.

You can't really get much closer. A child process (which is what your
Python program is) cannot alter the environment (env variables,
current directory, wtc) of its parent process (the CMD shell which
started the Python program). [There may be extremely hacky low-level
ways round this, but it's true is essence].

Unlike Python, batch files can do this, as they are run by the CMD
shell itself, rather than as a subprocess. In effect, they have
special abilities not available to normal programs.

Paul.

PS You can do something similar by using a BAT file to run a Python
program which prints a CD command that the BAT file reads and
executes, but that comes under my definition of "hacky" :-)


More information about the python-win32 mailing list