This simple command sequence runs expected in the Windows\' CMD shell:
dir & echo hello
will list the files and direct
You can also use cmd /V /C
(with /V
to enable delayed expansion).
That is great to set an environment variable for just one command in Windows cmd.exe
:
cmd /V /C "set "name=value" && echo !name!"
value
Note the usage of double-quotes in set "name=value"
to avoid the extra space after value
.
For instance, without double-quotes:
cmd /V /C "set name=value && echo '!name!'"
'value '
You would need to think to remove the space between value
and &&
:
cmd /V /C "set name=value&& echo '!name!'"
'value'
But using double-quotes makes the assignment more explicit.