[問題] command line 訊息存取

看板C_and_CPP (C/C++)作者 (傻傻)時間16年前 (2009/11/27 11:38), 編輯推噓8(8018)
留言26則, 5人參與, 最新討論串1/1
請教各位大大一下 有人知道如何將command line的訊息或者將compiler後的錯誤訊息 另存成txt或讀取嗎? ex: void __fastcall TForm1::Button1Click(TObject *Sender) { system("bcc32 test.cpp"); Edit1->Text = (從compiler後的命令視窗中所讀取錯誤訊息) } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.210.112.66

11/27 11:57, , 1F
用IDE tool的, 通常compile後或run-time的output window
11/27 11:57, 1F

11/27 11:58, , 2F
會有另存檔案或者直接copy->paste的功能(至少VC有啦)
11/27 11:58, 2F

11/27 11:58, , 3F
console的訊息如果是stdout出來的, 本來就可以直接pipe
11/27 11:58, 3F

11/27 11:59, , 4F
導向(如console指令後加>>或>)成一個檔案, 但是如果導到
11/27 11:59, 4F

11/27 11:59, , 5F
stderr的可能就沒辦法導向, 這種的msg text要再研究@_@"
11/27 11:59, 5F

11/27 12:39, , 6F
stderr應該可以用 2> 導吧 我只知道Unix-Like是這樣
11/27 12:39, 6F

11/27 12:42, , 7F
剛在win7下面試了 stdout 可以用 > stderr 可以用 2>
11/27 12:42, 7F

11/27 12:46, , 8F
原來stdout與stderr就只是兩個不同的stream啊....Orz
11/27 12:46, 8F

11/27 12:47, , 9F
感謝n版大, 以前看到stderr就放著給它爛....XD
11/27 12:47, 9F

11/27 13:06, , 10F
consoleApp.exe 1>stdout_plus_stderr.txt 2>&1
11/27 13:06, 10F

11/27 13:06, , 11F
Windows 可以這樣同時輸出 stdout 跟 stderr
11/27 13:06, 11F

11/27 13:06, , 12F
bash 聽說可以 &> 但是 Windows 測試不出來
11/27 13:06, 12F

11/27 13:09, , 13F
讀取的話,用IO redirect還是什麼,有點忘了,懶得找
11/27 13:09, 13F

11/27 13:11, , 14F
不是 << 還是 < 嗎?_?
11/27 13:11, 14F

11/27 13:12, , 15F
原PO想要做的應該還有其他方法,一時想不起來關鍵字
11/27 13:12, 15F

11/27 13:29, , 16F
謝謝大家指導...我繼續研究看看再跟大家分享
11/27 13:29, 16F

11/27 13:56, , 17F
V大,我剛試一個簡單程式用cout<<"hello"<<endl故意missing ;
11/27 13:56, 17F

11/27 13:58, , 18F
用bcc32 test.cpp > error.txt 可以work但 2>卻不行
11/27 13:58, 18F

11/27 13:59, , 19F
這是代表我compiler後的訊息是stdout?
11/27 13:59, 19F

11/27 14:16, , 20F
Hmm~~算是吧, 除非bcc同時丟向兩個stream, 不然只在一個
11/27 14:16, 20F

11/27 14:16, , 21F
收到也挺合理的, 一般compile完給你的訊息我也想不出來
11/27 14:16, 21F

11/27 14:16, , 22F
有什麼理由要丟stderr去, 通常正常給user看的放stdout,
11/27 14:16, 22F

11/27 14:17, , 23F
發生了什麼內部錯誤給該程式(本例為bcc)者自己除錯用的
11/27 14:17, 23F

11/27 14:18, , 24F
這類資訊我才會試著用stderr stream去丟@_@"
11/27 14:18, 24F

11/27 14:34, , 25F
應該是bcc比較特立獨行吧?
11/27 14:34, 25F

11/27 14:34, , 26F
gcc 就會把錯誤訊息丟到 stderr
11/27 14:34, 26F
文章代碼(AID): #1B3qcgFO (C_and_CPP)
文章代碼(AID): #1B3qcgFO (C_and_CPP)