1

I am making my college project like codepad.org.

Can anyone help in that how can I compile C and C++ program with C# in ASP.NET?

I have tried this code:

        Process proc = new Process();
        proc.StartInfo.FileName = "tc.exe";
        proc.StartInfo.RedirectStandardOutput = true;
        proc.Start();
        string output = proc.StandardOutput.ReadToEnd();

but it is giving error:

"The Process object must have the UseShellExecute property set to false in order to redirect IO streams."

and there is no method like "UseShellExecute".

Is this the correct way of doing or is there any other method?

2
  • 1
    bing.com/search?q=UseShellExecute Commented Mar 21, 2014 at 7:05
  • 1
    thanx for the help but i think its not working for me because "proc.StartInfo.FileName = "tc.exe";" this line is opening tc nothing else Commented Mar 22, 2014 at 6:25

2 Answers 2

2

It's all on MSDN.

ProcessStartInfo.UseShellExecute Property

So you code would just need the UseShellExecute property set to false.

Process proc = new Process();
proc.StartInfo.FileName = "tc.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
string output = proc.StandardOutput.ReadToEnd();
Sign up to request clarification or add additional context in comments.

4 Comments

thanx for the help but i think its not working for me because "proc.StartInfo.FileName = "tc.exe";" this line is opening tc nothing else
Well of course, you will need to specify which file to compile as well. something like proc.StartInfo.Arguments = "myfile.c"; (or whatever parameters tc.exe takes, but that wasn't the question).
i am taking input from user, so i have to store that TextBox data in to a file, how can i do that... Thanx
StackOverflow is a site where you can get answers to specific problems after trying to solve them yourself. Saving a file is something that you almost can't fail at if you google it quickly so that is something for you to learn. If you get problems with it after trying, it should be a new question and not a comment on an answer on another question.
2

use this ProcessStartInfo.UseShellExecute Property

Gets or sets a value indicating whether to use the operating system shell to start the process

proc.StartInfo.UseShellExecute = false;

Process proc = new Process();
proc.StartInfo.FileName = "tc.exe";
proc.StartInfo.UseShellExecute = false;
proc.StartInfo.RedirectStandardOutput = true;
proc.Start();
string output = proc.StandardOutput.ReadToEnd();

1 Comment

thanx for the help but i think its not working for me because "proc.StartInfo.FileName = "tc.exe";" this line is opening tc nothing else

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.