Reputation: 2855
All I want to do is:
I need to do this in one line using cmd.exe starting from a different drive
I would do this like this:
c:
cd temp
dir
so in one statement so far I have:
cmd /c c: & cd\temp & dir
But this just gives me dir for the P: directory which I start from. How can I get dir returned from c:\temp?
I can't run a batch file and it must be in a one-line statement.
Upvotes: 37
Views: 99192
Reputation: 49260
You may want to invoke CD with the /d option, thus not only changing the current directory on drive c: but also going there (in case you are not already on that drive).
cmd /c "cd /d c:\temp && dir"
Upvotes: 56
Reputation: 9389
you use && or & to separate multiple commands
if the cmd window is already opened and running from command line
c: && cd\temp && dir
or
cmd /c && c: && cd\temp && dir
Upvotes: 8
Reputation: 14346
You want quotes around that command line:
cmd /c "cd c:/ & dir"
Upvotes: 4