commonutil.runprogram

執行程式相關輔助函式 / Program invoking helpers

stdout_of_command(*cmd)[source]

執行給定的指令,並留存 STDOUT 的輸出並傳回。須注意因內容為儲存於記憶體中,因此程式如果有大量輸出可能會造成記憶體用盡。

Run given command and return the content of STDOUT. Caution: The content of STDOUT is kept in memory. Memory might be exhausted if the command generates huge amount of output.

Parameters:*cmd – 要執行的指令 / Command to invoke
Returns:一個 (data_stdout, retcode,) 形式的 tuple 物件,分別表示程式輸出到 STDOUT 的內容,以及程式結束時的傳回碼。

Tuple object in (data_stdout, retcode,) form. The resulted tuple represents output in STDOUT and the return code of given command respectively.