【发布时间】:2011-03-12 09:01:40
【问题描述】:
我想在 Vala 中执行一个命令(比如 ls),比如 Python os.system 函数,或者更好的是 popen 函数。有什么想法吗?
【问题讨论】:
标签: function system command vala
我想在 Vala 中执行一个命令(比如 ls),比如 Python os.system 函数,或者更好的是 popen 函数。有什么想法吗?
【问题讨论】:
标签: function system command vala
好的,明白了:Glib.Process.spawn_command_line_sync。
【讨论】:
最好使用包posix。
然后,只需执行Posix.system("command"),它会返回一个 int。
【讨论】:
您可以将GLib.Process.spawn_command_line_sync 用作:
public static int main (string[] args) {
string ls_stdout;
string ls_stderr;
int ls_status;
try {
Process.spawn_command_line_sync ("ls",
out ls_stdout,
out ls_stderr,
out ls_status);
// Output: <File list>
print ("stdout:\n");
// Output: ````
print (ls_stdout);
print ("stderr:\n");
print (ls_stderr);
// Output: ``0``
print ("Status: %d\n", ls_status);
} catch (SpawnError e) {
print ("Error: %s\n", e.message);
}
return 0;
}
【讨论】: