Okay, I learned that one can use &
or &&
to combine multiple commands into a single line, but it seems that variables that are set
Try the following:
cmd.exe /v /c "set foo=hello, world & echo !foo!"
The /v
argument enables delayed variable expansion. This allows you to access variables' values at execution time rather than at parse time (the default). You do this by writing !foo!
instead of %foo%
(with this /v
option turned on).
Instead of passing /v
, you can also turn delayed variable expansion on permanently via the registry, which obviously affects the entire system:
[HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor]
"DelayedExpansion"= (REG_DWORD)
1=enabled 0=disabled (default)