简体   繁体   中英

Program started from batch file starts in background

I have a batch file that I run from a flash drive. This file attempts to

1. Close 2 programs
2. Update data on the computer based on the data on the flash drive
3. Restart the programs

The code in this batch is:

taskkill /IM "MyProgram".exe
taskkill /f /fi "imagename eq MyProgram.exe"

copy e:\File1.xml C:\Folder\SubFolder1\Themes\Data\File1.xml /Y
copy e:\File2.xml C:\Folder\SubFolder1\Themes\Data\File2.xml /Y
copy e:\File3.xml C:\Folder\SubFolder2\Themes\Data\File3.xml /Y
copy e:\File4.xml C:\Folder\SubFolder2\Themes\Data\File4.xml /Y

start /MAX "" "C:\Folder\SubFolder2\MyProgram.exe"
start /MAX "" "C:\Folder\SubFolder1\MyProgram.exe"

The first two steps work fine, with the commands that are on lines 1-6. My issue starts with step 3 and the commands on lines 7 and 8.

Is there something wrong with the batch commands?

EDIT: After digging a little more, I have found that the programs appear to be starting in the background. When looking at task manager, the programs appear in the "Background Processes" section instead of showing in the foreground as expected.

What I believe is happening is your program does not know where the configuration files are located because the working directory is where the batch file started itself. So your program is looking for its files on your usb drive. By using the /D option with the START command it will switch the working directory to whatever path you set it to.

start "" /MAX /D "C:\Folder\SubFolder2\" MyProgram.exe

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM