2

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.

0

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Perfect, thank you! So, what's the difference between /K and /C? When should I use one as opposed to the other?
cmd.exe /? == /C runs the command and terminates, /K runs the command keeping the cmd process alive and active when finished.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.