Click to See Complete Forum and Search --> : cmd.exe with multiple commands


0xC0000005
January 19th, 2006, 11:32 AM
According to the documentation for cmd.exe multiple commands can be specified by enclosing each with quotes and seperating them by &&.

If I run cmd.exe (Start/Run...) like this:
cmd /K path

I get a display of the path variables (/K means keep the command window open).

If I run cmd.exe like this:
cmd /K dir

I get a directory listing.

So, how do I run both commands with one call? From the documentation I would assume like this:
cmd /K "path" && "dir"

But instead of both commands running I get the error message:
'dir" && "path' is not recognized as an internal or external command, operable program or batch file.

Note that I am trying to develop an application to do cmd.exe processing from a Windows program and this is a simplified example of the problem that is easy to reproduce.

Can anyone tell me how to execute both "path" and "dir" with a single call to cmd.exe?

MrViggy
January 19th, 2006, 12:33 PM
Try:
cmd /K "path && dir"
Viggy

NoHero
January 19th, 2006, 01:26 PM
Or create a temporary batch file (.bat) or command file (.cmd) and run this one using cmd.exe.

MrViggy
January 19th, 2006, 01:29 PM
Ahh, yes, the temporary batch file. I've used that myself for things like getting the current data/time.

Check out: http://home7.inet.tele.dk/batfiles/ There are a lot of cool batch file snippets there!

Viggy

0xC0000005
January 23rd, 2006, 08:18 AM
Thanks, it's working now with your help.