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.

Était-ce utile?

La 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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top