9

how can I run multiple commands at once from windows command line? In *nix environment I can do:

export VAR=foo; echo $VAR

The closest way I was able to find is this:

set VAR=foo & echo %VAR%

however when I "echo" the VAR is not set. I need all commands to be executed under the same process

4
  • Put them into a .bat/.cmd file. That'll run inside a single cmd.exe instance. Commented Aug 1, 2012 at 14:20
  • I cant do that. I'm running those commands remotely (and they are generated) and I have to run them like this: $ cmd /c commands Commented Aug 1, 2012 at 14:23
  • In the future, it'd be helpful to mention this sort of detail in advance. Commented Aug 1, 2012 at 14:24
  • batch file is not they wanted to do. You know that the sequence of commands works in one environment but not in the other so you very well understand the differences between environments. You do not ask to install Linux but you demand that asking people warned that Linux is not acceptable to them. Commented Oct 11, 2012 at 14:57

1 Answer 1

11

cmd /c call set VAR=foo & echo %VAR% - this worked ok i.e. set is called with "call set" .You can set call before each of the commands.

Sign up to request clarification or add additional context in comments.

5 Comments

In fact, it's enough to put call just before echo, and cmd is not needed either.
Well, I don't know why but this isn't working for me. The result of echo is always "%VAR%".
Andriy M: "cmd /c" is needed for me because it is a remote call so i have to put those commands as a parameter to cmd.exe
what if you set the expression after /c swithc in brackets? -> CMD /c "call set var=foo & call cmd /c call echo %var%"
Thank you. Whole trick was in calling echo in inner cmd process. So if i put it like this: CMD /c set VAR=foo & cmd /c echo %VAR% then it works fine.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.