I have a Windows forms application that I wont a console extension. I cant find a way to add a new console and also if there is a way how would i call it?
Asked
Active
Viewed 282 times
-2
-
1Do you want output like Console Application or you want to execute the console application? – mynkow Jul 11 '13 at 07:17
-
I don't understand what you mean, i wont to have a separate class controlling the Console Application. – Daniel Jones Jul 11 '13 at 07:29
-
I do not understand what you 'wont' to do. Give us an example. – mynkow Jul 11 '13 at 07:34
-
Check this: http://stackoverflow.com/questions/472282/show-console-in-windows-application – iAmd Jul 11 '13 at 07:37
-
Ok, I have a windows form application and i wont a Console application to pop up. that's all. – Daniel Jones Jul 11 '13 at 07:40
-
See [this answer](http://stackoverflow.com/a/15079092/366904). Also related: [How do I add a console like element to a c# winforms program](http://stackoverflow.com/q/252323), [how to run a winform from console application?](http://stackoverflow.com/q/277771) – Cody Gray - on strike Jul 11 '13 at 08:10
2 Answers
1
If you just want to pop up a Console application it is as simple as:
Process cmdProcess = new Process();
cmdProcess.StartInfo.FileName = "cmd";
cmdProcess.Start();

JeffRSon
- 10,404
- 4
- 26
- 51
0
If you want to call an Executable (output of a console application) from WinForms, then as @JeffRSon quoted
Process cmdProcess = new Process();
cmdProcess.StartInfo.FileName = "YourExecutablePath.exe";
cmdProcess.Start();
If you want an application to be run in Command Prompt then the code as:
System.Diagnostics.ProcessStartInfo psi = new System.Diagnostics.ProcessStartInfo("cmd.exe");
psi.CreateNoWindow = true;
psi.UseShellExecute = false;
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardError = true;
psi.WorkingDirectory = "Path of the Executable";
System.Diagnostics.Process process = System.Diagnostics.Process.Start(psi);
string sCommandLine = string.Format("YourExecutable.exe -{1}", YourParameterValues);
process.StandardInput.WriteLine(sCommandLine);
process.StandardInput.Flush();
process.StandardInput.Close();
process.WaitForExit();
process.Close();

hiFI
- 1,887
- 3
- 28
- 57