I have a USB flash drive with portable installs of Dropbox and emacs. One of the functions I want to run in emacs needs to have
sha1sum.exe in the path, so I also put coreutils on the USB. I am writing a batch file which:
- Puts the path to sha1sum.exe in PATH. (while I'm at it, also the path to emacs and Dropbox)
- Runs Dropbox in a separate process.
- Runs emacs.
Here is what I have:
set PATH="%PATH%;%~d0\pathtocoreutils\bin;%~d0\pathtodropbox;%~d0\pathtoemacs\bin" echo %PATH% timeout 10 start DropboxPortableAHK.exe timeout 10 runemacs.exe
When I run it in a new command window, the
echo commands give the expected results, but everything else gives errors indicating that the files are not on the path (including
timeout, which was added for debugging and is not in any of the new PATH entries):
'timeout' is not recognized as in internal or external command, executable program or batch file. The system cannot find the file DropboxPortableAHK.exe. 'timeout' is not recognized as in internal or external command, executable program or batch file. 'runemacs.exe' is not recognized as in internal or external command, executable program or batch file.
If I run it a second time in the same command window, then it works fine. Executing the same commands individually from the command line also works. Opening a new terminal will also cause the batch file to fail once. The behavior I'd like is to be able to run the batch file by clicking on it, but in that case, there is no ability to run it a second time in the same instance of
My first thought was that execution proceeded to the other commands before
set PATH= was complete, and
PATH was completely inaccessible. That's why I added the
timeouts. However, the fact that
echo %PATH% returns the correct updated value suggests that this isn't really the issue. Also, the failed
start opens a message box, and execution does not pass to the last two lines until it is done, yet these lines still fail.
Everything I've been able to turn up about setting
PATH in a batch file is for people trying to get the change to persist system-wide. The answers all suggest that the normal behavior is for
set PATH= to work within the same terminal instance, including later in the same batch file.
I'm testing on Windows 7 Professional sp1 without admin access.
What's going on here, and how can I fix it?