Home > Software design >  Trying to start multiple .exe files in order with a bat file but first line fails and second line is
Trying to start multiple .exe files in order with a bat file but first line fails and second line is

Time:10-08

My code in the .bat looks like this.

"C:\users\reshade injector.exe"
C:\pathtogame\game.exe "added argument"

"c:\users\reshade injector.exe" <- if I open the actual file, it opens a command window and waits for my other application to launch. Is this a console app?

C:\pathtogame\game.exe "added argument" <- this works and launches my game

Another issue is that when launching the first .exe, a command window stays open. How do I make the command window not appear?

Can anyone help me with these two problems?

*edit for clarity by opening the actual file, I mean double-clicking on the original reshade injector.exe. When opening reshade injector.exe, two cmd windows open. They close as soon as I launch the game.exe.

I can't seem to get the reshade injector.exe to launch through the .bat file.

CodePudding user response:

Batch will run any application it finds. If the application does not terminate (eg. it's waiting for user-input) then it will progress to the next instruction.

Some applications work by launching another (the user-interface) and then terminating, leaving the second application resident.

There's no way to tell without observing which approach any random application may take.

So - your batch should execute a file named c:\users\reshade injector.exe.

You say that "fails". Is there an error message generated? You would likely need to run the batch from the "command prompt" to see that message. Note that the Space between reshade and injector must be in the actual filename. If injector.exe is a file in a subdirectory called reshade, then you need a backslash between reshade and injector.

Having resolved the actual name of the first executable, try

@echo off
setlocal
start "" "firstexecutablename"
start "" "secondexecutablename" "arguments"

The first two lines prevent "command echoing" which is used for debugging and establish a "local environment" which ensures the "environment" for the batch file remains unchanged when the batch terminates. In the current case, these two lines are probably unnecessary, but it's SOP for batch files.

The batch should then close its session and window once it has attempted to launch the two applications.

The "" following start becomes the window-title. It can be any quoted string you like, but should not be omitted as start uses the first quoted string it finds as a window-title and may not recognise it as part of the executable/arguments.

  • Related