最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

C# 調(diào)用exe傳參,并獲取打印值的實(shí)例

 更新時(shí)間:2021年04月16日 11:06:58   作者:小薯仔  
這篇文章主要介紹了C# 調(diào)用exe傳參,并獲取打印值的實(shí)例,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧

調(diào)用方法:

string baseName = System.IO.Directory.GetCurrentDirectory();
 // baseName+"/"
 // string fileName = @"C:\Users\59930\Desktop\20170605\WindowsFormsApp1\WindowsFormsApp1\WindowsFormsApp1\bin\x86\Debug\WindowsFormsApp1.exe";
 string fileName = baseName + @"\CardRead.exe";
 string para = "1.exe " + code;          
 Process p = new Process();
 p.StartInfo.UseShellExecute = false;
 p.StartInfo.RedirectStandardOutput = true;
 p.StartInfo.FileName = fileName;
 p.StartInfo.CreateNoWindow = true;
 p.StartInfo.Arguments = para;//參數(shù)以空格分隔,如果某個(gè)參數(shù)為空,可以傳入””  
 p.Start();
 p.WaitForExit();
 string output = p.StandardOutput.ReadToEnd();

調(diào)用的exe 返回值中寫

Console.Write(mmma); 

補(bǔ)充:c#調(diào)用外部exe的方法有簡(jiǎn)單,有復(fù)雜的。

最簡(jiǎn)單的就是直接利用process類

using System.Diagnostics;
Process.Start(" demo.exe");

想要詳細(xì)設(shè)置的話,就

  public static void RunExeByProcess(string exePath, string argument)
  {
   //創(chuàng)建進(jìn)程
   System.Diagnostics.Process process = new System.Diagnostics.Process();
   //調(diào)用的exe的名稱
   process.StartInfo.FileName = exePath;
   //傳遞進(jìn)exe的參數(shù)
   process.StartInfo.Arguments = argument;
   process.StartInfo.UseShellExecute = false;
   //不顯示exe的界面
   process.StartInfo.CreateNoWindow = true;
   process.StartInfo.RedirectStandardOutput = true;
   process.StartInfo.RedirectStandardInput = true;
   process.Start();
 
   process.StandardInput.AutoFlush = true;
   //阻塞等待調(diào)用結(jié)束
   process.WaitForExit();
  }

如果想獲取調(diào)用程序返回的的結(jié)果,那么只需要把上面的稍加修改增加返回值即可:

public static string RunExeByProcess(string exePath, string argument)
  {
   //創(chuàng)建進(jìn)程
   System.Diagnostics.Process process = new System.Diagnostics.Process();
   //調(diào)用的exe的名稱
   process.StartInfo.FileName = exePath;
   //傳遞進(jìn)exe的參數(shù)
   process.StartInfo.Arguments = argument;
   process.StartInfo.UseShellExecute = false;
   //不顯示exe的界面
   process.StartInfo.CreateNoWindow = true;
   process.StartInfo.RedirectStandardOutput = true;
   process.StartInfo.RedirectStandardInput = true;
   process.Start();
 
   process.StandardInput.AutoFlush = true;
 
   string result = null;
   while (!process.StandardOutput.EndOfStream)
   {
    result += process.StandardOutput.ReadLine() + Environment.NewLine;
   }
   process.WaitForExit();
   return result;
  }

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教。

相關(guān)文章

最新評(píng)論

嘉祥县| 崇义县| 深泽县| 嵊州市| 前郭尔| 宣恩县| 温宿县| 乌审旗| 蒙城县| 武隆县| 珠海市| 萨嘎县| 柳江县| 屯留县| 盘锦市| 凤山市| 镇沅| 五常市| 西乌珠穆沁旗| 博白县| 永顺县| 萨嘎县| 铜川市| 高陵县| 梅河口市| 孟州市| 青冈县| 永福县| 台北市| 博白县| 巩留县| 寿宁县| 当涂县| 牟定县| 蕲春县| 渭源县| 榆林市| 双峰县| 兴宁市| 武隆县| 南康市|