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
2009-12-23 21:30:40
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.
2009-12-23 21:34:10
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
2009-12-25 00:15:26
+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
2009-12-23 21:35:42
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
2009-12-24 00:34:41
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"" ?
2009-12-24 06:52:19
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
2009-12-24 23:38:29