You cannot "execute cpp files", you can only execute (some) executable files.
As far as I can understand, you are trying to compile.
One problem I can see is this: you should not use "cmd" "/c". You should use "command" only, with proper command line parameters including input file(s). Everything else depends on how you compile, what compiler do you use, do you build a project file or solution (which you could do with MSBuild.exe), etc.
Another problem is: redirecting of
StandardOutput
is not always enough. Generally, you also need to redirect
StandardError
; this is done in exact same way. I hope this will resolve your problem.
[EDIT #1]
You tried to re-post this question. Please don't do it — it cannot help you anyway. Instead, use the same page, in this case, this page: use "Improve question" above, comment on question/answer, reply to existing comments.
[EDIT #2]
In response to code sample of the OP's comment to this answer:
First of all, never ever use repeated string concatenation (+). Do you know that strings are
immutable? In your case, use
string.Format
. In other cases (like loops), use
System.Text.StringBuilder
.
I have no idea what is
ExecuteCommandSync
. You can use the static method
Process.Start(ProcessStartInfo)
or the instance method
Process.Start()
with appropriate
StartInfo
assigned to the instance of
Process
. For synchronization, use the instance method
Process.WaitForExit
.
It's the best to do it in a separate thread and synchronized its output with your UI thread. Please see my past solutions on UI thread invocation:
Control.Invoke() vs. Control.BeginInvoke()[
^],
Problem with Treeview Scanner And MD5[
^].
If is not clear: "unable to handle exceptional cases like errors in cpp file". There are no "exceptional cases like errors" in CPP files. All you have is build errors. Exceptions are not thrown. Errors are reported in text output which is either
StandardOutput
or
StandardError
. You need to
redirect both. After all, run compilation command manually — you should get all the output in your redirected streams, check it up.
After all, see
http://msdn.microsoft.com/en-us/library/system.diagnostics.process.aspx[
^] — but thoroughly.
I'm just curious: are you going to run linker as well?
Making an UI like Visual Studio is quite possible, I've done it.
[EDIT #3]
One more thing. I noticed you are hard-coding file path names. Hope this is only for experimental purposes during development.
There are no situations where a hard-coded path name can be useful. You should always calculate path names for files, get it from configuration files, etc.
—SA