env var=value application.exe
is possible. Write following batch script, name it env.bat
and place it somewhere in a directory from your PATH variable. Please read Command Line arguments (Parameters) and setlocal articles for further explanation.
env.bat script:
@setlocal
@set "%~1=%~2"
@%3
Above script applies to given simple command but would require to be a bit elaborated to accept line parameters like env var=value application.exe action input output
etc.
Before edit:
set var=value&application.exe&set var=
i.e. set variable then run a console application and then remove variable.
Another approach:
cmd /C "set var=value&application.exe"
i.e. start a new instance of the Windows command interpreter and within it set variable then run a console application; for /C
switch meaning see cmd /?
:
/C Carries out the command specified by string and then terminates
Here &
ampersand must be escaped in the command specified. You could choose any:
cmd /C "set var=value&application.exe"
or
cmd /C set var=value^&application.exe
Note proper spacing as well:
↓ allowed space
cmd /C "set var=value & application.exe"
↑ this is harmful space as "%var%" would be "value " then
note trailing space ↑