On Linux, when I want to prepare the environment of a program before starting it, I'm using a wrapper script:
export JAVA_HOME=...
cd /some/folder
exec ./tool "$@"
How would I do the last line, especially the "$@", on Windows?
Note: I'm wrapping commands which take a lot of arguments (like java or mvn), so I need a solution which works for > 10 arguments.
Being able to exec would be nice but is only a minor concern.
Probably something like:
@echo off
setlocal enableextensions
set JAVA_HOME=...
cd ...
start "" .\sometool %*
endlocal
Setlocal localizes environment changes to the script (see setlocal /? for details), and %* means 'all script parameters'. The start command is a cmd.exe command that spawns an executable.
The start command has odd parsing rules; the first quoted string on its command line is considered to be a console window title, which is superfluous if you are not spawning a console window. This means that a command like this won't work as expected:
start "C:\Program Files (x86)\Microsoft Office\Office14\excel.exe"
If you run this command, you will spawn a new instance of cmd.exe with the quoted string as its console window title, which is clearly not what was intended. Instead, you have to write this:
start "" "C:\Program Files (x86)\Microsoft Office\Office14\excel.exe"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With