what am I doing wrong with my Process.Start?

  • Thread starter Thread starter Mark Reed
  • Start date Start date
M

Mark Reed

I am trying to have a button that brings up the cmd prompt and then does
a DIR listing.

I am using:

private void button2_Click(object sender, System.EventArgs e)
{
System.Diagnostics.Process.Start("cmd.exe","dir");
}

It does everything except the dir.
 
Should be:

..Start(@"cmd.exe", "/C ""dir""");

or something similar (didn't test this exact code). Just running cmd.exe
dir (try it on the command line) doesn't work - cmd.exe /C "dir" DOES work,
so you have to pass the parameters like that.
 
I must be doing something wrong. I have:

System.Diagnostics.Process.Start(@"cmd.exe", "/C","dir");

but get:
C:\Documents and Settings\Administrator\My Documents\Visual Studio Projects
\WindowsApplication6\Form1.cs(90): No overload for method 'Start' takes
'3' arguments

Being a newbie, Im stuck on this.


M. Reed
 
I have it working somewhat...but the console window closes right away.

I am using:

System.Diagnostics.Process.Start("cmd.exe", "/c dir");
 
GOT IT!

Sorry for the threaded posts as I worked thru it...

System.Diagnostics.Process.Start("cmd.exe", "/k dir");
is what I needed... wrong flag earlier...has /c and needed /k
 
Back
Top