2012-12-12 104 views
5

在D中異步調用其他進程的首選方式是什麼?我的用例是調用svn status檢查退出狀態,並解析其標準輸出和錯誤。異步進程調用

回答

5

我覺得std.stdio.popen是你想要什麼:

void popen(string command, in char[] stdioOpenmode = "r"); 

File使用它,你得到的輸出;是這樣的:

File f; 
f.popen("svn status", "r"); 
char[] line; 
string result; 
while (f.readln(line)) 
    result ~= line; 
return result; 

或者你可以使用std.process.shell這顯然可以實現這個要求(並拋出出錯的ErrnoException)。