问题
as the title said I need to run exactly two commands in one line using cmd in windows 10. How is it possible?
回答1:
to run two commands use &. Both commands will be executed:
dir file.txt & echo done
Use && to execute the second command only if the first command was successful:
dir existentfile.txt && echo done
Use || to run the second command only if the first command failed:
dir nonexistentfile.txt || echo not found
You can combine:
dir questionablefile.txt && (echo file exists) || (echo file doesn't exist)
回答2:
Easy to pick one from general syntax:
Run multiple commands (cmd1, cmd2, cmd3) in one line:
cmd1 & cmd2 & cmd3 // run all commands from left to right (& => all)cmd1 && cmd2 && cmd3 // run all commands from left to right, stop at 1st fail (&& => till fail)cmd1 | cmd2 | cmd3 // run all commands from left to right, stop at 1st fail, also | is pipe which sends cmd1 output to cmd2 & so on, so use when if you want to pass outputs to other commands - (| => till fail + pass output of left to right)cmd1 || cmd2 || cmd3 // run all commands from left to right, stop at 1st success (|| => till good)
Summary:
& => run all
&& => run L2R till fail
| => run L2R till fail + pass output of left to right
|| => run L2R till good
where, L2R is left to right
Hope that helped.
回答3:
cmd1;cmd2
cmd1&cmd2
cmd1|cmd2
来源:https://stackoverflow.com/questions/50394413/how-to-run-multiple-commands-in-one-line-using-cmd-in-windows-10