If you're not opposed to using Windows Powershell (you can simply execute powershell
in command prompt to enter an instance of the Powershell shell), this is the closest way to do what you are asking.
echo new_dir | %{mkdir $_; cd $_}
Adapted from simonwo's xargs answer.
However, if for certain reasons you are unable to use Powershell, then this is a method to achieve very similar behavior. The issue being simply that you are now using variables instead of redirecting output.
SET "d=new_dir" && call mkdir %^d% && call cd %^d%
Adapted from jeb's oneliner answer.
Similarly, for a slightly more readable input string and portable method (due to the limitations of call
) than the above, you can use the following. However, note that you will be moved into a new separate instance of the command line shell.
cmd /v /k "set d=new_dir && mkdir !d! && cd !d!"
The /v
argument enables delayed variable expansion, and the /k
argument carries out the command by the string but remains without terminating.
Adapted from Blogbeard's oneliner answer.