Start a Java program from batch file and exit without waiting - batch-file

I have a small Windows batch script that is executed from within a game application (the user experience is important here) that is called to start a Java program among other things. With the command javaw I hide console output from the user of the game to improve experience, however, the console window remains open from the batch file execution and doesn't close until the Java code is finished executing.
The first solution I tried was to use the start command, but I am unable to pass any parameters to the java program and it fails accordingly.
start javaw -jar jar-file-here.jar args...
How should I write a batch file that will start a Java program with the correct variables, and close without waiting for Java to close?
Edit:
My parameters contain quotes ( " ), so I am unable to contain them all in quotes without confusing the command.

The first argument accepts a window title. Here is the command with the adjustment made:
start "Window Title Here" javaw -jar jar-file-here.jar args...

Related

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

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.
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.

batch file to exe to auto run when computer start

I am a new programmer, i have created a batch file to open a website but i want that batch file to run when the computer starts.
Here's the code:
#echo off
:top
start iexplore.exe http://www.website.com
timeout 3
goto top
While i do think Arescet's answer will work, i am more in favor of using Windows' Task Scheduler.
Simply create a new task :
Assign it's trigger to be At Startup :
and add a new action to Start a program giving it the path to your batch file:
I believe this is a cleaner approach which also provides you with logging and history should you decide to do more things in your batch file later on
Type run into windows search, type shell:startup in the prompt, press enter, Then, create a shortcut of your program, and move the shortcut into the startUp folder.
On note of your code, the start command should have a blank title as "", and quotes around the application name and parameters passed, like:
start "" "iexplore.exe" "http://www.website.com"

Batch Files - Closing Opened Text Files

I currently have a Windows batch file that runs an .exe file that uses a text file. I am trying to have the Windows batch file run the .exe file multiple times. This, however, requires the use of the same text files to read from. The command prompt gives me the error that the ".txt could not be opened" (I assume from this that it is already open.)
I am trying to see if there is a way in a .bat file to system call to kill that specific text file. The suggestions I see online are to use 'taskkill notepad.exe', but that returns "invalid argument" because the program doesn't open Notepad to use the text file.
Any suggestions would be appreciated.
It sounds like your existing script fails because the first instance of the exe is still open when the second instance starts.
One thing worth trying (and this depends on the nature of the application you are invoking) is to start the executable using the START /WAIT /B ... command. This makes the command interpreter wait for the program to exit before it moves onto the next command, so as long as nothing else is locking the text files you should be OK to move onto the next command.

exit batch processing even if calling program still running

I think it's a simple question, but I don't realize its solution.
I have a batch file that calls an EXE program. It's working fine, but I'd like to close the CMD window without having to click on it.
It's like this:
#echo off
[...]
call EXEprogram.exe
[...]
exit
I want the CMD window vanishes, even if the EXEprogram is still running, but the control doesn't return to the batch file, to execute the EXIT command. I tested using CALL command calling another batch file that calls EXEprogram and also, don't using the CALL command, but result is the same: CMD window shows that EXEprogram is still running and the control doesn't come back to execute EXIT command.
Ideas?
Use the start command instead of call:
start EXEprogram.exe
Type start /? for further details.

Run batch files sequentially

I want to ask you all how to run batch files sequentially in Windows.
I have tried :
start /w batchfile_1.bat
start /w batchfile_2.bat
..
start /w batchfile_n.bat
but I have to close the previous .bat file process manually (e.g. by clicking) before continuing into the next one.
Is there any solution to do this automatically without me doing the manual closing previous .bat program every time?
Thanks a lot.
I would check the solutions to this question: Run Multiple batch files
Taken from the answer in the link.
Use call:
call bat1.cmd
call bat2.cmd
By default, when you just run a batch file from another one control will not pass back to the calling one. That's why you need to use call.
Basically, if you have a batch like this:
#echo off
echo Foo
batch2.cmd
echo Bar
then it will only output
Foo
If you write it like
#echo off
echo Foo
call batch2.cmd
echo Bar
however, it will output
Foo
Bar
because after batch2 terminates, program control is passed back to your original batch file.
If you are in love with using START, you could have your batch files end with the EXIT command. That will close the windows created by the start command.
#echo off
.
.
:: Inspired coding
.
.
exit
I'm not sure but based on your comments, the following seems to be happening when you run that sequence of START commands:
A START /W command is invoked and starts a batch file.
The batch file starts executing and runs a program.
The batch file finishes and its console window remains open, but the program continues running.
The START /W command that was used to run the batch file is still executing because the console window remains open.
You wait until the program terminates, then you close the console window, and then the next START /W command is invoked, and everything is repeated.
Now, if you place EXIT at the end of every batch file you want to run sequentially, that makes situation worse because it causes the console window to close after the batch script completes, and that in turn ends the corresponding START /W command and causes another one to execute, even though the program invoked by the batch script may still be running. And so the effect is that the batch scripts (or, rather, the programs executed by them) run simultaneously rather than sequentially.
I think, if this can be solved at all, you need to move the START /W command and put it in every batch file in front of (every) command that that batch file executes and doesn't wait for the termination of. That is, if your batchfile_1.bat runs a program.exe, change the command line to START /W program.exe, and similarly for other relevant commands in other batch files.

Resources