start /b javaw with custom path to java home issue - batch-file

I'm writing a windows batch script to start my Java program in the background, using javaw.
The issue comes when I let the user have a custom path to the Java Home. Let's say in an example when the path to Java home is: C:\Users\Sample User\Desktop\java (notice the space in the path), when I try running the start command, it breaks because of the spaces.
Example:
#echo off
set CUSTOM_JAVA_HOME=C:\Users\Federico Einhorn\Desktop\java
set CP=myjar.jar;../lib/*;.
set JAVA_PARAMS=-myOption -Xmx1024M -classpath %CP%
set JAVA_CLASS=com.myorg.MyClass
set RUN_OPTS=%JAVA_PARAMS% %JAVA_CLASS% start
start /b "%CUSTOM_JAVA_HOME%/bin/javaw" %RUN_OPTS%
That start command fails as the CUSTOM_JAVA_HOME has spaces.
Windows cannot find '-myOption'. Make sure you typed the name
correctly, and then try again.
This doesn't happen when I run my jar with regular java:
"%CUSTOM_JAVA_HOME%/bin/java" %RUN_OPTS%
Is there a way to solve this?

Start sees "%CUSTOM_JAVA_HOME%/bin/javaw" as a title.
The fix is to include a title yourself, even a blank one:
Start "" /B "%CUSTOM_JAVA_HOME%\bin\javaw" %RUN_OPTS%

Related

Problem with starting Games from Epic Games in a Batch Script

So i'm writing on a Batch Script to Optimize Games and i found the following way to start Games from Epic Games in cmd:
start "" "com.epicgames.launcher://apps/0584d2013f0149a791e7b9bad0eec102%3A6e563a2c0f5f46e3b4e88b5f4ed50cca%3A9d2d0eb64d5c44529cece33fe2a46482?action=launch&silent=true"
This is now for GTAV and it works fine typing it manually in cmd however as soon when i put it in a Batch Script it just opens the Epic Games Window but doesn't start the Game.
I also tried to run the command in a seperate cmd window like that:
start cmd.exe "start "" "com.epicgames.launcher://apps/0584d2013f0149a791e7b9bad0eec102%3A6e563a2c0f5f46e3b4e88b5f4ed50cca%3A9d2d0eb64d5c44529cece33fe2a46482?action=launch&silent=true""
But it still does nothing. It just says that it can't find silent or it's written wrong.
Also the echo shows that are spaces in the command now:
start cmd.exe "start "" "com.epicgames.launcher://apps/0584d2013f0149a791e7b9bad0eec102A6e563a2c0f5f46e3b4e88b5f4ed50ccaA9d2d0eb64d5c44529cece33fe2a46482?action=launch & silent=true""
Maybe someone else knows what's wrong or why it doesn't work?
Instead of using the Url use the shortcut .url file created by epic launcher, in my case the shortcut is saved on Desktop with file name "Game Name.url".
#echo off
cd "C:\Users\username\Desktop"
start "" "Game Name.url"
exit
It also auto launches Epic Launcher if not running.
Note: Remove any special character in file name if present.
My skills with cmd are rusted and I cant recreate this specific code, but did you try:
start "com.epicgames.launcher://apps/0584d2013f0149a791e7b9bad0eec102A6e563a2c0f5f46e3b4e88b5f4ed50ccaA9d2d0eb64d5c44529cece33fe2a46482?action=launch"
::epic games
::check if EpicGamesLauncher.exe is running already
tasklist /fi "ImageName eq EpicGamesLauncher.exe" /fo csv 2>NUL | find /I "EpicGamesLauncher.exe">NUL
if "%ERRORLEVEL%"=="1" (
::start epic games itself
:: has to be opened like a website link
start "" com.epicgames.launcher://apps
::clears screen not to confuse user during timeout due to weird start command error ("The system cannot find the drive specified.")
cls
echo EpicGamesLauncher.exe is NOT running!
echo Starting Epic Game Launcher...
:: waits x seconds for epic launcher to load
TIMEOUT /T 15
)
::this will start if epic games is open, if not it will just open epic games itself, need double %% because this is a batch file
::com.epicgames.launcher://apps/0584d2013f0149a791e7b9bad0eec102%3A6e563a2c0f5f46e3b4e88b5f4ed50cca%3A9d2d0eb64d5c44529cece33fe2a46482?action=launch&silent=true
start "" com.epicgames.launcher://apps/0584d2013f0149a791e7b9bad0eec102%%3A6e563a2c0f5f46e3b4e88b5f4ed50cca%%3A9d2d0eb64d5c44529cece33fe2a46482?action=launch&silent=true
exit
Since this was modified 2 months ago, i hope someone will still see this:
The batch command is the following:
START "" "A:\Program Files (x86)\Epic Games\Launcher\Portal\Binaries\Win64\EpicGamesLauncher.exe" com.epicgames.launcher://apps/0584d2013f0149a791e7b9bad0eec102:6e563a2c0f5f46e3b4e88b5f4ed50cca:9d2d0eb64d5c44529cece33fe2a46482?action=launch&silent=true
The first "" is just a title for the new "window" you're creating. If not provided the cmd will think the exe will be the title and the url the right programm to start. Just bad style
The EpicGamesLauncher.exe will be the right programm to start. I found it with help of the first answer of this question. Just look for the "com.epicgames.launcher" protocol.
The third part u get by creating a Shortcut to your game in eg. (RMB on Game -> Manage -> Create Desktop Link) Then go in the shortcut properties and under webdocument you can find the url property. This is the third part but you need to decode the url encoding. For GTA i had multiple "%3A" in it, this translates to a simple ":".
It works on my Win10 maschine. And i hope it will work on your maschine as well.

How to run batches NOT using cmd.exe (like Cmder.exe?)

I've recently installed cmder (or simply 'Commander') portable console emulator for windows, and really like the functionalities it comes with. But how can you (if at all) run batches through it like you can with the Windows command line?
The details:
If you write...
cd C:\test\
REM executeSomething.exe
Pause
... to a textfile and save it as a .bat file you can do can do pretty much anything just by double-clicking that file. I've got a work-flow where I launch a web-application through a batch file. Sometimes this applicaton launches automatically in Chrome, and sometimes it does not. In that case, I'll have to copy and paste a URL to Chrome manually. And that's a real pain. With cmder.exe that's much easier, but I'll have to manually navigate to a folder and start the application through Commander it manually without the luxury of a .bat file.
The functionality I'm trying to run automatically with cmder.exe is simply changing a folder and starting an executable file, specifically Jupyter Lab:
cd C:\jupyterlab\
jupyter lab
Pause
I've tried various approaches with:
#echo off
set CMDER_ROOT=C:\Cmder
start %CMDER_ROOT%\vendor\conemu-maximus5\ConEmu.exe /icon "%CMDER_ROOT%\cmder.exe" /title "Homestead VM" /loadcfgfile "%CMDER_ROOT%\config\ConEmu.xml" /cmd cmd /k "%CMDER_ROOT%\vendor\init.bat cd %CD% && %~1"
as described here, but with no success. The example above does launch commander, but also raises a syntax error:
Current directory: C:\batches
Command to be executed: "C:\Windows\system32\cmd.exe" /k
"C:\Cmder\vendor\init.bat cd C:\batches && "
I'm obviously on to somehting here since I'm able to start Commander, but I'm not sure how to edit the remaining code to run the necessary steps. I do realize that the /title "Homestead VM" part just edits the title of the Commander window:
but I have no idea about the rest.
If this just isn't possible, I'm going to have to try to reassociate .bat files in Control Panel > Default Programs > Associate a filetype, but I'm hoping to avoid that.
Thank you for any suggestions!
System info:
Windows 7, 64 bit
Commander v1.3.12
Edit 1: My (failed) attempt trying to follow a suggestion from Gerhard Barnard
I've saved a file named please.cmd to C:\Windows\System32 that contains this:
#echo off
if not defined CMDER_ROOT set "CMDER_ROOT=C:\Cmder"
start %CMDER_ROOT%\vendor\conemu-maximus5\ConEmu.exe /icon "%CMDER_ROOT%\cmder.exe" /title "Homestead VM" /loadcfgfile "%CMDER_ROOT%\config\ConEmu.xml" /cmd cmd /k "%CMDER_ROOT%\vendor\init.bat cd %CD% && %~1"
I've also saved a file named SObatch.bat in C:\batches that contains this:
if not defined myComs set myComs=0 && please %~0
#echo off
ping localhost
echo %userprofile%
pause
Upon double-clicking SObatch.bat a Windows prompt is opened, and the pings are run:
I just narrowed the window to leave out real-world user-names. But the ping functions are being run and the usual responses are returned.
So I guess it still seems that I've broken something.
Create a file called please.cmd and save it to C:\Windows\System32 as administrator. It should then exist as c:\Windows\System32\please.cmd
#echo off
if not defined CMDER_ROOT set "CMDER_ROOT=C:\Cmder"
start %CMDER_ROOT%\vendor\conemu-maximus5\ConEmu.exe /icon "%CMDER_ROOT%\cmder.exe" /title "Homestead VM" /loadcfgfile "%CMDER_ROOT%\config\ConEmu.xml" /cmd cmd /k "%CMDER_ROOT%\vendor\init.bat cd %CD% && %*"
Now when you create a batch files you need to make some changes in the top of each batch file you want. You would need to add the below line to the very top of the script.
"%systemroot%\system32\please.cmd" "%~f0" && goto :eof
You can also from cmd please command to launch it from the cmder shell. Example:
please ping localhost

Create a batch file to run an .exe with an additional parameter

I need a batch file which will do the following:
1. Open CMD and navigate to a location C:/Users/...../program.exe
2. Run the program.exe with an additional command to point it to a config file:
e.g. "program.exe C:/Users/..../configFile.bgi"
How can I do this?
I tried this but with no luck:
start "C:\Users\Ben\Desktop\BGInfo\bginfo.exe C:\Users\Ben\Desktop\BGInfo\dc_bginfo.bgi"
pause
Update
I've used the solution provided by Ganesh (below) and came up with this:
cd C:\Users\Ben\Desktop\BGInfo\
bginfo.exe C:\Users\Ben\Desktop\BGInfo\dc_bginfo.bgi
I've tested it on a local machine (changing the directories) but on the server (with the directory above) it does not work...
The folder directory with batch file:
The error
in batch file abc.bat
cd c:\user\ben_dchost\documents\
executible.exe -flag1 -flag2 -flag3
I am assuming that your executible.exe is present in c:\user\ben_dchost\documents\
I am also assuming that the parameters it takes are -flag1 -flag2 -flag3
Edited:
For the command you say you want to execute, do:
cd C:\Users\Ben\Desktop\BGInfo\
bginfo.exe dc_bginfo.bgi
pause
Hope this helps
You can use
start "" "%USERPROFILE%\Desktop\BGInfo\bginfo.exe" "%USERPROFILE%\Desktop\BGInfo\dc_bginfo.bgi"
or
start "" /D "%USERPROFILE%\Desktop\BGInfo" bginfo.exe dc_bginfo.bgi
or
"%USERPROFILE%\Desktop\BGInfo\bginfo.exe" "%USERPROFILE%\Desktop\BGInfo\dc_bginfo.bgi"
or
cd /D "%USERPROFILE%\Desktop\BGInfo"
bginfo.exe dc_bginfo.bgi
Help on commands start and cd is output by executing in a command prompt window help start or start /? and help cd or cd /?.
But I do not understand why you need a batch file at all for starting the application with the additional parameter. Create a shortcut (*.lnk) on your desktop for this application. Then right click on the shortcut, left click on Properties and append after a space character "%USERPROFILE%\Desktop\BGInfo\dc_bginfo.bgi" as parameter.
Found another solution for the same. It will be more helpful.
START C:\"Program Files (x86)"\Test\"Test Automation"\finger.exe ConfigFile="C:\Users\PCName\Desktop\Automation\Documents\Validation_ZoneWise_Default.finger.Config"
finger.exe is a parent program that is calling config solution.
Note: if your path folder name consists of spaces, then do not forget to add "".

CMD Batch command "start /wait" not working in Windows 8.1?

I'm working on a very simple bat file script that worked fine in Windows 7, but seems to be having issues in Windows 8. It relies heavily on "start /wait" to execute 1 file at a time. It seems that the "start" command works just fine. However, given the folder structure, I have referenced each item as such in a command:
start /wait ./folder1/app1.exe
start /wait ./folder2/app2.exe
start /wait ./folder3/app3.exe
While this worked just fine in W7. In Windows 8.1, this results in an error message stating: "Windows cannot find '.\folder1\app1.exe'. Make sure you typed the name correctly, and then try again."
So... Did MS replace the .\ wildcard in Windows 8 with something else? Or change it just slightly?
Yes, I know. This isn't really programming (still studying C/CPP), but any insight would be greatly appreciated.
./ is not a wildcard. * and ? are wildcards - they match any number of any characters /one any-character.
/ is a switch indicator. \ is a directory separator. Dangerous to confuse the two - it confuses cmd.
.\ means 'relative to the current directory`. Perhaps you should display the current directory using
echo %cd%
to make sure that cmd's idea of the current directory and yours agree. Also make sure the targets exist and are not hidden files.
I had the same problem with a cmd file on my usb drive.
In Windows 7 my application started with ...
START /WAIT %usbDrive%\Truecrypt\TrueCrypt.exe /volume %usbDrive%\%Container% /k %usbDrive%\Truecrypt\Truecrypt.key /cache /wipecache /quit
... but in Windows 8.1 it has not waited to put my password in the TrueCrypt screen.
As a workaround for both Windows versions this works for me fine now.
START %usbDrive%\Truecrypt\TrueCrypt.exe /volume %usbDrive%\%Container% /k %usbDrive%\Truecrypt\Truecrypt.key /cache /wipecache /quit
:CHECK
ping -n 2 localhost 1>NUL 2>NUL
TASKLIST /FI "IMAGENAME eq TrueCrypt.exe" > TrueCrypt.txt
FIND /N "TrueCrypt.exe" TrueCrypt.txt 1>NUL 2>NUL
IF %ERRORLEVEL%==0 ( GOTO CHECK ) ELSE ( DEL TrueCrypt.txt )
At first you start the program you want, then you need a mark to go back and check if your program is still running. The next thing is to wait about 2 seconds (for ping -n ... you can also use timeout). Then you can filter the tasklist with the exeutable name and write it in a check text file. With the find command you can grep in the check file... Finally the last line, if the application is not in the tasklist anymore the check text file will be deleted otherwise the cmd is jumping to the check mark.
I hope it will help

Starting an exe in the same console

Quick and simple question: I have a batch file that calls for some .exe like so:
START /WAIT GVE %opt%
My problem is that the program starts in a new console, is their anyway to make it start in the same console ? I've tried /NOCONSOLE option without success.
Thanks
I think you just need the /B option (assuming the exe is a console app)
start "" /b /wait gve %opt%

Resources