看板 C_Sharp 關於我們 聯絡資訊
※ 引述《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
senjor:話說拿掉還是一樣不行...字串一樣是空的...是不是某些exe 10/31 09:19
senjor:是process控管不到的例外呢? 10/31 09:19
senjor:找到解決方式了...利用cmd 下參數的方法... 10/31 10:12