views:

3998

answers:

4

Hi i want to invoke the Console application from my application but i would like to capture all the output generated in the console. (Remember, i dont want to save the information first in a file and then relist as i would love to receive it as live)

+12  A: 

This can be quite easily achieved using the ProcessStartInfo.RedirectStandardOutput Property. A full sample is contained in the linked MSDN documentation; the only caveat is that you may have to redirect the standard error stream as well to see all output of your app.

mdb
+4  A: 

Use ProcessInfo.RedirectStandartOutput to redirect the output when creating your console process.

Then you can use Process.StandardOutput to read the program output.

The second link has a sample code how to do it.

Franci Penov
A: 

Assuming you are invoking the app from console, Doesn't "your_command" > "fileName" do that? Or is it something else

questzen
A: 
Process p = new Process();   // Yeni nesne yarat...
p.StartInfo.UseShellExecute = false;  //   Shell kullanma...
p.StartInfo.RedirectStandardOutput = true;   //   Çıkışı yönlendir....
p.StartInfo.FileName = "c:\\python26\\python.exe";   //   Python klasörümüz ve derleyicimizin adı...
p.StartInfo.Arguments = "c:\\python26\\Hello_C_Python.py";   //   verilecek yani çalıştırılacak python scriptimizin yolu...

http://pythontr.org/index.php?option=com_content&view=article&id=50:python-script-lerinin-c-ile-caltrlmas-execute-python-script-in-c&catid=31:makale&Itemid=66

livetogogo