Resolves startup external program issues.
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Diagnostics;4 usingSystem.Linq;5 usingSystem.Text;6 usingSystem.Threading.Tasks;7 8 namespaceOuterexe9 {Ten class Program One { A Static voidinputfiles () - { - //In dir:outer the //Input main.cpp & data.in & Data.out - } - - Static voidMain (string[] args) + { - inputfiles (); + Try A { atProcess Run = Process.Start ("Outer\\main.bat"); - if(Run! =NULL) - { - run.waitforexit (); - if(run.hasexited) -Console.WriteLine ("External Program has exited."); in } - Else to { + Run.kill (); -Console.WriteLine ("External Program had exited by force."); the } * } $ Catch(Exception Exception)Panax Notoginseng {Console.WriteLine (Exception). Message); } - the stringErrorString = System.IO.File.ReadAllText ("Outer\\error"); + stringAnswer = System.IO.File.ReadAllText ("Outer\\data.out"); A stringYouranswer = System.IO.File.ReadAllText ("Outer\\test.out"); the + if(ErrorString! ="") - { $Console.WriteLine ("compiling error:\n"+errorstring); $ Console.readkey (); - return; - } the if(Youranswer = =Answer) -Console.WriteLine ("Accepted");Wuyi ElseConsole.WriteLine ("wrong Answer"); the Console.readkey (); - } Wu } -}
View Code
In debug, there is a Outer folder.
Use main.bat to coordinate the implementation of the program.
1 @echo off 2 g++ outer\main.cpp-o outer\main 2> outer\error3 outer\main < Outer\data. in > Outer\test.out
View Code
Note that g++ 's execution directory is not Outer, but debug, which is determined by the bat feature.
Visual Studio Form & DataBase (4)