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

C# 調用exe傳參,并獲取打印值的實例

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

調用方法:

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ù)以空格分隔,如果某個參數(shù)為空,可以傳入””  
 p.Start();
 p.WaitForExit();
 string output = p.StandardOutput.ReadToEnd();

調用的exe 返回值中寫

Console.Write(mmma); 

補充:c#調用外部exe的方法有簡單,有復雜的。

最簡單的就是直接利用process類

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

想要詳細設置的話,就

  public static void RunExeByProcess(string exePath, string argument)
  {
   //創(chuàng)建進程
   System.Diagnostics.Process process = new System.Diagnostics.Process();
   //調用的exe的名稱
   process.StartInfo.FileName = exePath;
   //傳遞進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;
   //阻塞等待調用結束
   process.WaitForExit();
  }

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

public static string RunExeByProcess(string exePath, string argument)
  {
   //創(chuàng)建進程
   System.Diagnostics.Process process = new System.Diagnostics.Process();
   //調用的exe的名稱
   process.StartInfo.FileName = exePath;
   //傳遞進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;
  }

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

相關文章

最新評論

成安县| 营山县| 霞浦县| 雷波县| 嘉禾县| 涟源市| 南部县| 星座| 塔城市| 房山区| 杨浦区| 曲阳县| 专栏| 德阳市| 达州市| 沂水县| 巨野县| 浦城县| 治县。| 饶河县| 宁陕县| 金堂县| 达拉特旗| 承德市| 古丈县| 大港区| 冕宁县| 东乌珠穆沁旗| 玉环县| 浮山县| 开封县| 黎平县| 卢龙县| 婺源县| 积石山| 桃源县| 东海县| 田东县| 正镶白旗| 汤阴县| 乡城县|