.bat file trouble.

eryksun eryksun at gmail.com
Sun Sep 20 16:53:12 CEST 2015


On 9/18/15, Christian Gollwitzer <auriocus at gmx.de> wrote:
> Am 18.09.15 um 11:06 schrieb bobertini at googlemail.com:
>
>> We originally thought that it was because it was missing the files:
>> process_init.py and process_global_variables.py however they are
>> right there in the same directory.
>
> Concerning that, windows usually runs a .bat file in the directory where
> it is situated, so putting the python fies there /should/ work, but you
> can also set this using the right-click menu (execute in...), if you
> make a link to the desktop.

It's fragile to depend on being started by Explorer or a shell link.
For example, if the batch is run from an existing cmd shell, then it
runs with cmd's current working directory. Or another process could
run the batch file with a different working directory. If you actually
want the batch to find the scripts relative to its own directory, then
it should use the %0 environment variable, which references the
fully-qualified path of the batch file. Getting just the directory,
i.e. its [d]rive and [p]ath, is expressed as %~dp0. Note that this
path includes a trailing backslash.


More information about the Python-list mailing list