c 中重定向windows控制台程式的輸出資訊

2021-09-08 11:55:47 字數 585 閱讀 4551

這個問題來自論壇提問,答案如下.這只是乙個簡單的ipconfig命令.如果是複雜的,比如oracle的exp之類的命令,能在呼叫的時候顯示出來,還是相當酷的.

using

system;

using

system.windows.forms;

namespace

delegate

void dreadline( string

strline);

private

void excutecommand( string strfile, string

args, dreadline onreadline)

p.waitforexit();

} private

void button1_click( object

sender, eventargs e)

private

void printmessage( string

strline)

} }/*

何問起 hovertree.com

*/

推薦:

控制台重定向stdout stderr

通常,乙個控制台 命令提示符 應用程式或命令的輸出將傳送到兩個單獨的流.常規的輸出傳送到標準出 stdout 並將錯誤訊息傳送到標準錯誤 stderr 當你重定向控制台輸出使用 符號,只重定向標準輸出.要重定向stderr,必須指定 2 的重定向符號.這將選擇第二個輸出流stderr。kill hu...

控制台輸出重定向到Memo

函式runcmd void fastcall tform1 runcmd ansistring cmdline,tstrings result else createpipe hreadpipe,hwritepipe,null,1024 screen cursor crhourglass try d...

控制台輸入輸出重定向

一般來講gui程式不能使用stdin和stdout,但是有時有些特殊需要,希望gui程式也有控制台,如 乙個程式,既可以以gui方式執行,又可以如果使用者在控制台裡打程式名的話,就以控制台程式的方式執行。通過allocconsole 和 attachconsole 這兩個win api就能實現上面的...