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 返回值中寫
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)文章
Unity實(shí)現(xiàn)繞任意軸任意角度旋轉(zhuǎn)向量
這篇文章主要為大家詳細(xì)介紹了Unity實(shí)現(xiàn)繞任意軸任意角度旋轉(zhuǎn)向量,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-01-01
c#將list類型轉(zhuǎn)換成DataTable方法示例
將List類型轉(zhuǎn)換成DataTable的通用方法,大家參考使用吧2013-12-12
關(guān)于C#執(zhí)行順序帶來(lái)的一些潛在問(wèn)題
這篇文章主要給大家介紹了關(guān)于C#執(zhí)行順序帶來(lái)的一些潛在問(wèn)題,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家學(xué)習(xí)或者使用C#具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-08-08
C#實(shí)現(xiàn)字符串倒序遍歷的方法小結(jié)
這篇文章主要為大家詳細(xì)介紹了C#中實(shí)現(xiàn)字符串倒序遍歷的常見(jiàn)方法,文中的示例代碼講解詳細(xì),具有一定的借鑒價(jià)值,有需要的小伙伴可以參考下2024-02-02
c#模擬平拋運(yùn)動(dòng)動(dòng)畫的方法詳解
本篇文章是對(duì)使用c#模擬平拋運(yùn)動(dòng)動(dòng)畫的方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下2013-06-06
Winform開發(fā)中使用下拉列表展示字典數(shù)據(jù)的幾種方式
這篇文章介紹了Winform開發(fā)中使用下拉列表展示字典數(shù)據(jù)的幾種方式,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-09-09
C#中WinForm控件的拖動(dòng)和縮放的實(shí)現(xiàn)代碼
本篇文章主要介紹了C#中WinForm控件的拖動(dòng)和縮放的實(shí)現(xiàn)代碼,C# WinForm控件的拖動(dòng)和縮放是個(gè)很有用的功能,有興趣的可以了解一下。2017-01-01

