Visual Studio Form & DataBase (4)

來源:互聯網
上載者:User

標籤:

解決啟動外部程式問題。

 1 using System; 2 using System.Collections.Generic; 3 using System.Diagnostics; 4 using System.Linq; 5 using System.Text; 6 using System.Threading.Tasks; 7  8 namespace OuterExe 9 {10     class Program11     {12         static void InputFiles()13         {14             // In dir: Outer15             // Input main.cpp & data.in & data.out16         }17 18         static void Main(string[] args)19         {20             InputFiles();21             try22             {23                 Process Run = Process.Start("Outer\\main.bat");24                 if (Run != null)25                 {26                     Run.WaitForExit();27                     if (Run.HasExited)28                         Console.WriteLine("External program has exited.");29                 }30                 else31                 {32                     Run.Kill();33                     Console.WriteLine("External program has exited by force.");34                 }35             }36             catch(Exception exception)37             { Console.WriteLine(exception.Message); }38             39             string ErrorString = System.IO.File.ReadAllText("Outer\\error");40             string Answer = System.IO.File.ReadAllText("Outer\\data.out");41             string YourAnswer = System.IO.File.ReadAllText("Outer\\test.out");42             43             if (ErrorString != "")44             {45                 Console.WriteLine("Compiling error:\n" + ErrorString);46                 Console.ReadKey();47                 return;48             }49             if (YourAnswer == Answer)50                 Console.WriteLine("Accepted");51             else Console.WriteLine("Wrong Answer");52             Console.ReadKey();53         }54     }55 }
View Code

在 debug 裡面,有個 Outer 檔案夾。

用 main.bat 統籌程式的執行。

1 @echo off2 g++ Outer\main.cpp -o Outer\main 2> Outer\error3 Outer\main < Outer\data.in > Outer\test.out
View Code

要注意的是 g++ 的執行目錄不是 Outer,而是 debug,這是 bat 的特點決定的。

Visual Studio Form & DataBase (4)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.