Question

I'm just switching over to C# from Java, so bear with me. From what I've read in several places online, you need to run commands with the following syntax:

Process.Start("cmd.exe","/C <<command>>");

But, when I do that, the command window opens and immediately closes.

So, I try it without the /C for kicks.

Process.Start("cmd.exe","<<command>>");

This time, the command window stays open, but nothing happens -- no command is run. I've tried it with even the simplest commands.

What am I doing wrong? I'm sure it's a noobish mistake.

Thank you in advance. Using Visual C# 2010 Express.

Was it helpful?

Solution

You need /K

Process.Start("cmd.exe", "/k dir c:\\");

Note that running cmd.exe dir c:\ from the shell would not work either as the command line is not valid without a leading /K or /C switch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top