tags:

views:

192

answers:

4

i need to run a program from the cmd, how can i do it in c#?

+5  A: 

If you want to run a program, as from the command line, you would use Process.Start

It wouldn't show a command prompt though, unless it is a console app.

Rick Mogstad
To get around this, you can launch `cmd.exe` with the `/C` switch and pass the name of the program you really want to run.
Anon.
Sure, you could run it from cmd that way, but it won't show up as a console app or anything. If you need it to be running from cmd then, you can do as Anon says.
Rick Mogstad
+4  A: 

Process.start() is your friend.

No Refunds No Returns
+1  A: 

Process.Start, which is in the System.Diagnostics namespace.

Note that you can supply a ProcessStartInfo object if you want to customize things, such as redirecting input/output.

Guvante
A: 

If you want to run a program or a batch file it is quite easy.

Process myProcess = new Process();

myProcess.StartInfo.FileName = "MyProgram.exe";
myProcess.StartInfo.Arguments = "1st_argument 2nd_argument" 
myProcess.StartInfo.CreateNoWindow = false;

try
{
    myProcess.Start();
    myProcess.WaitForExit();
}

This way you can pass arguments to your program or batch and decide to show or hide the executing console.

Regards.

Ucodia
if my argument are"-q -dNODISPLAY -dSAFER -dDELAYBIND -dWRITESYSTEMDICT -dSIMPLE -c save -f ps2ascii.ps "c:\test.pdf" -c quit >"c:\test.txt""then myProcess.StartInfo.Arguments = "-q -dNODISPLAY -dSAFER -dDELAYBIND -dWRITESYSTEMDICT -dSIMPLE -c save -f ps2ascii.ps "c:\test.pdf" -c quit >"c:\test.txt"" ?
That should do the trick, give it a try! What is clearly sure is that using arguments is not be a problem. The Process class has been designed for.
Ucodia