Re: [問題] 關於Process要怎麼放入參數?

看板C_Sharp作者 (暗黑貴公子)時間17年前 (2008/10/31 01:03), 編輯推噓2(201)
留言3則, 1人參與, 最新討論串2/2 (看更多)
※ 引述《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
話說拿掉還是一樣不行...字串一樣是空的...是不是某些exe
10/31 09:19, 1F

10/31 09:19, , 2F
是process控管不到的例外呢?
10/31 09:19, 2F

10/31 10:12, , 3F
找到解決方式了...利用cmd 下參數的方法...
10/31 10:12, 3F
文章代碼(AID): #192UZFuX (C_Sharp)
文章代碼(AID): #192UZFuX (C_Sharp)