winform呼叫外部exe,win7下正常 win10錯誤
代碼如下:
Process p = new Process();
p.StartInfo.FileName = "pre_test\\pre_test.exe";//需要執行的檔案,我把他放在了網站目錄下
// p.StartInfo.FileName = "cmd.exe";//需要執行的檔案,我把他放在了網站目錄下
p.StartInfo.UseShellExecute = false; //必需
p.StartInfo.RedirectStandardOutput = true;//輸出引數設定
p.StartInfo.RedirectStandardInput = true;//傳入引數設定
p.StartInfo.CreateNoWindow = true;
// p.StartInfo.Arguments = "D:\\ppp";//引數以空格分隔,如果某個引數為空,可以傳入””
//p.StartInfo.StandardErrorEncoding =System.Text.Encoding.UTF8;//傳入引數設定
p.Start();
p.StandardInput.WriteLine("d:\\result");
StreamReader _StreamReader = p.StandardOutput;
string line = _StreamReader.ReadToEnd();
string _Resultindex =line.Substring( line.IndexOf("[[")+2,6);
Console.WriteLine($"獲取的值是:{_Resultindex}");
p.WaitForExit();//等待程式執行完退出行程
p.Close();
_StreamReader.Close();
根據win10下提示 p.StandardInput沒有接收到引數
uj5u.com熱心網友回復:
沒有人回復,額額額額已經解決uj5u.com熱心網友回復:
無非兩個原因,權限問題和路徑問題uj5u.com熱心網友回復:
uj5u.com熱心網友回復:
已經解決。。。uj5u.com熱心網友回復:
<add key="exePath" value="D:\Pro\bin\Debug\Pro.exe"/>
internal static void startProgram()
{
int index = ConfigurationManager.AppSettings["exePath"].Trim().ToString().LastIndexOf("\\");
string filePath = ConfigurationManager.AppSettings["exePath"].Trim().ToString().Substring(0, index);
string exePath = ConfigurationManager.AppSettings["exePath"].Trim().ToString();
Process process = new Process { StartInfo = { FileName = exePath, WorkingDirectory = filePath, Arguments = "test" } };
process.Start();
}
uj5u.com熱心網友回復:
string line = _StreamReader.ReadToEnd();string _Resultindex =line.Substring( line.IndexOf("[[")+2,6);
看下這個 是否問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/127376.html
標籤:C#
