7

Python os.system関数、より良いのはpopen関数のように、Valaでコマンド(lsなど)を実行したいと思います。何か案が ?

4

3 に答える 3

18

OK、わかりました:Glib.Process.spawn_command_line_sync。

于 2010-07-06T15:33:03.247 に答える
13

パッケージを使用することをお勧めしますposix。次に、Posix.system("command")intを返すdoを実行します。

http://www.valadoc.org/posix/Posix.system.html

于 2010-08-01T14:48:46.837 に答える
1

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;
}
于 2020-06-21T07:54:57.500 に答える