C# 調(diào)用exe傳參,并獲取打印值的實(shí)例
調(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 返回值中寫(xiě)
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ò)誤或未考慮完全的地方,望不吝賜教。
- c# 實(shí)現(xiàn)打印機(jī)狀態(tài)查詢與阻塞打印
- c#使用Aspose打印文件的示例
- 如何利用C#打印九九乘法表
- c# winform 解決PictureBox 無(wú)法打印全部圖片的問(wèn)題
- C#操作Word打印的示例
- C#操作excel打印的示例
- C# 打印網(wǎng)頁(yè)不顯示頁(yè)眉頁(yè)腳的實(shí)現(xiàn)方法
- C#實(shí)現(xiàn)掃描槍掃描二維碼并打印(實(shí)例代碼)
- C#利用PrintDocument定制打印單據(jù)的小例子
- C#打印PDF文檔的10種方法(小結(jié))
- C# TSC打印二維碼和條形碼的實(shí)現(xiàn)方法
- C# winform打印excel的方法
- c# 如何實(shí)現(xiàn)web打印插件
相關(guān)文章
c#實(shí)現(xiàn)識(shí)別圖片上的驗(yàn)證碼數(shù)字
這篇文章主要介紹了c#實(shí)現(xiàn)識(shí)別圖片上的驗(yàn)證碼數(shù)字的方法,本文給大家匯總了2種方法,有需要的小伙伴可以參考下。2015-11-11C#?崩潰異常中研究頁(yè)堆布局的詳細(xì)過(guò)程
最近遇到一位朋友的程序崩潰,發(fā)現(xiàn)崩潰點(diǎn)在富編輯器 msftedit 上,這個(gè)不是重點(diǎn),重點(diǎn)在于發(fā)現(xiàn)他已經(jīng)開(kāi)啟了 頁(yè)堆,由于 頁(yè)堆 和 NT堆 的內(nèi)存布局完全不一樣,這一篇結(jié)合我的了解以及 windbg 驗(yàn)證來(lái)系統(tǒng)的介紹下 頁(yè)堆,需要的朋友可以參考下2022-10-10Quartz.Net實(shí)現(xiàn)原理及使用方法詳解
這篇文章主要介紹了Quartz.Net實(shí)現(xiàn)原理及使用方法詳解,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-12-12c#判斷網(wǎng)絡(luò)連接狀態(tài)的示例分享
這篇文章主要介紹了使用c#判斷網(wǎng)絡(luò)連接狀態(tài)的示例,需要的朋友可以參考下2014-02-02Unity給物體添加多個(gè)Tag的實(shí)現(xiàn)
這篇文章主要介紹了Unity給物體添加多個(gè)Tag的實(shí)現(xiàn),文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2021-04-04