Re: [問題] 關於Process要怎麼放入參數?
※ 引述《senjor (哞哞)》之銘言:
: 程式碼如下
: {
: Process p = new Process();
: p.StartInfo.FileName = @"c:\svm\svm-predict.exe";
: p.StartInfo.Arguments = "train.svm train.model svm.out";
: p.StartInfo.UseShellExecute = false;
: p.StartInfo.RedirectStandardOutput = true;
: p.Start();
: p.WaitForExit();
: string s = p.StandardOutput.ReadToEnd();
: }
: 但是程式好像完全不理會我的參數(或者沒有wait);
: 然後就直接跳過流程
: 但是如果沒有參數的話照理來說s應該會是svm-predict.exe的help訊息
: 可是s卻是空字串
: 讓我懷疑是p沒有做到WaitForExit的動作
: Process會有什麼不會wait的例外嗎?
: 還是說我添加參數的方式錯誤?
WaitForExit() 是無限期等待 process 關閉後才會往下執行
而這時再讀取 p.StandardOutput 會是空字串, 因為 process 已經結束
所以, 假設以同步方式來撰寫, 要像底下這樣, 拿掉 p.WaitForExit()
就能讀取到該 process => stdio 的資料
p.Start();
string s = p.StandardOutput.ReadToEnd();
而 p.StandardOutput.ReadToEnd(); 這行是會等待 process => 丟資料 => stdio
--
私が生存への道は
今も未來も唯一つ
私自身の闇黑のためだ
即ち「ハ・ル・ヒ」
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.133.168.73
推
10/31 09:19, , 1F
10/31 09:19, 1F
→
10/31 09:19, , 2F
10/31 09:19, 2F
推
10/31 10:12, , 3F
10/31 10:12, 3F
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):