views:

97

answers:

2

These days I'm working on a VB.NET application which can be used to edit, compile and run C programs. Can someone tell me how I can call a cl.exe process from within my VB program and also that how do I run the program in the console widow itself.

Presently I have only the editor ready. With that one can type in a program and save it with a ".c" extension. Now there are 2 buttons on my form - "Compile" and "Run". When the user clicks on the "Compile" button, the program should be passed to the cl.exe process and the errors should be displayed in another textbox or the DOS(black screen itself). And when the user clicks on the "Run" button, the ".exe" file which just got created should get executed.

Is there any way to attach some files along with my program so that the people who do not have "C" installed in their computers can also edit, compile and run C programs using my application?

+1  A: 

You can use the System.Diagnostics.Process class to do this.

You can launch any executable using the Start method. You an pass arguments, etc, just like you would from the command line.

Added

You can redirect the output of the program using the Process.StartInfo.RedirectStandardOutput property.

There are similar methods for redirecting errors, input, etc.

David Stratton
@David - How do I redirect the errors, input and output to/from a textbox from the compiler results?
Arjun Vasudevan
Using the Process.StartInfo.RedirectStandardOutput, RedirectStandardError, ec. See here: http://msdn.microsoft.com/en-us/library/system.diagnostics.process.standardoutput.aspx
David Stratton
@David - Thanks, I'll try out the links.
Arjun Vasudevan
A: 

To capture the output of the compiler or the compiled and linked program, use the System.Diagnostics.Process.StandardOutput property to retrieve a System.IO.StreamReader instance.

Judge Maygarden
@Judge Maygarden - I'll check out the property from the MSDN Library installed in ma system. Thanks for the help.
Arjun Vasudevan