-2

Possible Duplicate:
Run console application from other console app

In my program there is a TextBox in which the user should write the program (simple) that I ask him to do.

How to run his program to make sure that he had done what I told him? Nice to know that I had already do an auto compiling of the program and make sure there is no syntax error.

Community
  • 1
  • 1
mkam
  • 145
  • 1
  • 5

2 Answers2

0

C# Compiler - codeproject describes the steps in order to have a C# compiler using CodeDom Compiler API :

  1. Create an instance of CSharpCodeProvider (VBCodeProvider for Visual Basic)
  2. Obtain interface for ICodeCompiler
  3. Provide CompilerParameters for compiler options
  4. Compile source code using CompileAssemblyFromSource method of ICodeCompiler interface
  5. Process CompilerResults
  6. Execute generated application if there were no errors
Tilak
  • 30,108
  • 19
  • 83
  • 131
  • how can i get the values obtained after the user run his program? for example if the goal of the program is to give the biggest number from a list of numbers.. how can i get the number that the user's program give to test if it is really the biggest? – mkam Jan 06 '13 at 13:56
  • For that you need to use [InterprocessCommunication](http://stackoverflow.com/questions/84855/what-is-the-best-choice-for-net-inter-process-communication). There are multiple ways, Clibroard, WCF, Remoting, file based, named pipe, memory mapped files etc. – Tilak Jan 06 '13 at 15:10
  • i tried to use{ int result = f.ExitCode; } but i get result=0 always – mkam Jan 06 '13 at 16:32
  • ExitCode will always be 0 if application is terminated successfully. That is expected behavior. If you are new to interprocesscommunication, you can start [here](http://msdn.microsoft.com/en-us/library/aa446520.aspx) – Tilak Jan 06 '13 at 16:35
0

If the compiled program is only reading and writing from standard input and output, use ProcessStartInfo with RedirectStandardInput and RedirectStandardOutput set. Start the process with Process.Start(ProcessStartInfo)

See Redirecting Standard Input/Output using the Process Class for an example.

Tilak
  • 30,108
  • 19
  • 83
  • 131
Mitch
  • 21,223
  • 6
  • 63
  • 86