Top | ![]() |
![]() |
![]() |
![]() |
void | error | Run Last |
void | error-received | Run Last |
void | output-received | Run Last |
void | reaped | Run Last |
GCutProcessは外部コマンドの実行・通信・終了をカプセル化します。GCutProcessはエラーをGErrorとして報告します。エラーはgcut_assert_error()
を使うことにより簡単に検証できます。
外部コマンドはgcut_process_new()
、gcut_process_new_strings()
などのようなコンストラクタで指定します。この時点では外部コマンドは実行されません。gcut_process_hatch()
で指定された外部コマンドが実行されます。
Standard/Error outputs of external command are passed by
“output-received”/“error-received” signals
or GIOChannel returned by
gcut_process_get_output()
/gcut_process_get_error()
.
gcut_process_write()
writes a chunk to standard input of
external command.
外部コマンドの終了を待つためにはgcut_process_wait()
を使うことができます。無限待ちを避けるために、タイムアウトを指定することができます。
例:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
static GString *output_string; static GCutProcess *process; void cut_setup (void) { output_string = g_string_new(NULL); process = NULL; } void cut_teardown (void) { if (output_string) g_string_free(output_string, TRUE); if (process) g_object_unref(process); } static void cb_output_received (GCutProcess *process, const gchar *chunk, gsize size, gpointer user_data) { g_string_append_len(output_string, chunk, size); } void test_echo (void) { GError *error = NULL; process = gcut_process_new("echo", "XXX", NULL); g_signal_connect(process, "receive-output", G_CALLBACK(cb_output_received), NULL); gcut_process_run(process, &error); gcut_assert_error(error); gcut_process_wait(process, 1000, &error); gcut_assert_error(error); cut_assert_equal_string("XXX\n", output_string->str); } |
GCutProcess * gcut_process_new (const gchar *command
,...
);
Creates a new GCutProcess object that runs command
.
Since: 1.1.5
GCutProcess *
gcut_process_new_command_line (const gchar *command_line
);
Creates a new GCutProcess object that runs command_line
.
Since: 1.1.5
GCutProcess * gcut_process_new_va_list (const gchar *command
,va_list args
);
Creates a new GCutProcess object that runs command
.
Since: 1.1.5
GCutProcess * gcut_process_new_argv (gint argc
,gchar **argv
);
Creates a new GCutProcess object that runs command
.
Since: 1.1.5
GCutProcess *
gcut_process_new_strings (const gchar **command
);
Creates a new GCutProcess object that runs command
.
Since: 1.1.5
GCutProcess *
gcut_process_new_array (GArray *command
);
Creates a new GCutProcess object that runs command
.
Since: 1.1.5
void gcut_process_set_flags (GCutProcess *process
,GSpawnFlags flags
);
外部コマンドを実行するときのflags
を設定します。
Since: 1.1.5
GSpawnFlags
gcut_process_get_flags (GCutProcess *process
);
外部コマンドを実行する時のflags
を取得します。
Since: 1.1.5
void gcut_process_set_env (GCutProcess *process
,const gchar *name
,...
);
外部コマンドの環境変数を設定します。
process |
||
name |
最初の環境変数名。 |
|
... |
the value of |
Since: 1.1.5
gchar **
gcut_process_get_env (GCutProcess *process
);
外部コマンドの環境変数を取得します。
新しく割り当てられたNULL
終端の環境変数のリスト("名前1=値1", "名前2=値2", ..., NULL
)を返します。必要がなくなったらg_strfreev()
で開放してください。
Since: 1.1.5
gboolean gcut_process_run (GCutProcess *process
,GError **error
);
新しい外部プロセスを実行します。
Since: 1.1.5
GPid
gcut_process_get_pid (GCutProcess *process
);
実行している外部プロセスのプロセスIDを取得します。外部コマンドが実行されていない場合は0が返ります。
Since: 1.1.5
gint gcut_process_wait (GCutProcess *process
,guint timeout
,GError **error
);
実行中の外部プロセスが終了することをtimeout
ミリ秒待ちます。外部コマンドがtimeout
ミリ秒以内に終了しなかった場合は、GCUT_PROCESS_ERROR_TIMEOUT
エラーが設定され、-1が返ります。外部プロセスが実行されていない場合は、GCUT_PROCESS_ERROR_NOT_RUNNING
エラーが設定され、-1が返ります。
Since: 1.1.5
gboolean gcut_process_kill (GCutProcess *process
,gint signal_number
,GError **error
);
外部プロセスにsignal_number
シグナルを送ります。
Since: 1.1.5
gboolean gcut_process_write (GCutProcess *process
,const gchar *chunk
,gsize size
,GError **error
);
外部プロセスの標準入力にchunk
を書き込みます。
Since: 1.1.5
GIOStatus gcut_process_flush (GCutProcess *process
,GError **error
);
外部プロセスの標準出力から読み込んだデータ。
the status of the operation: One of
G_IO_STATUS_NORMAL
, G_IO_STATUS_AGAIN
, or
G_IO_STATUS_ERROR
.
Since: 1.1.5
GString *
gcut_process_get_output_string (GCutProcess *process
);
Since: 1.1.5
GString *
gcut_process_get_error_string (GCutProcess *process
);
Since: 1.1.5
GIOChannel *
gcut_process_get_input_channel (GCutProcess *process
);
外部プロセスの標準入力と結びついたGIOChannelを取得します。
Since: 1.1.5
GIOChannel *
gcut_process_get_output_channel (GCutProcess *process
);
外部プロセスの標準出力と結びついたGIOChannelを取得します。
Since: 1.1.5
GIOChannel *
gcut_process_get_error_channel (GCutProcess *process
);
外部プロセスのエラー出力に結びついたGIOChannelを返します。
Since: 1.1.5
GInputStream *
gcut_process_get_output_stream (GCutProcess *process
);
外部プロセスの標準出力と結びついたGInputStreamを取得します。
Since: 1.1.5
GInputStream *
gcut_process_get_error_stream (GCutProcess *process
);
外部プロセスの標準エラー出力に結びついたGInputStreamを返します。
Since: 1.1.5
guint
gcut_process_get_forced_termination_wait_time
(GCutProcess *process
);
オブジェクトが破棄されるときに行われる外部コマンド強制終了後に待つ時間(ミリ秒)を取得します。
Since: 1.1.5
void gcut_process_set_forced_termination_wait_time (GCutProcess *process
,guint timeout
);
オブジェクトが破棄されるときに行われる外部コマンド強制終了時に待つ時間(ミリ秒)を設定します。timeout
が0なら外部コマンドの終了を待ちません。デフォルト値は10です。
Since: 1.1.5
GCutEventLoop *
gcut_process_get_event_loop (GCutProcess *process
);
Gets a event loop using by the process
.
Since: 1.1.6
void gcut_process_set_event_loop (GCutProcess *process
,GCutEventLoop *loop
);
Sets a event loop for the process
. If loop
is NULL
,
the default GLib event loop will be used.
Since: 1.1.6
GCutProcess関連の操作で返されるエラーコード。
コマンドライン関連のエラー。 |
||
入出力エラー。 |
||
外部コマンドはすでに実行されています。 |
||
外部こもアンドが実行されていません。 |
||
不正なGCutProcessオブジェクトが渡されました。 |
||
不正なシグナルが渡されました。 |
||
許可がありません。 |
||
タイムアウト。 |
Since: 1.1.5
“error”
signalvoid user_function (GCutProcess *process, gpointer error, gpointer user_data)
Flags: Run Last
Since: 1.1.5
“error-received”
signalvoid user_function (GCutProcess *process, gchar *chunk, guint64 size, gpointer user_data)
Flags: Run Last
Since: 1.1.5
“output-received”
signalvoid user_function (GCutProcess *process, gchar *chunk, guint64 size, gpointer user_data)
Flags: Run Last
Since: 1.1.5
“reaped”
signalvoid user_function (GCutProcess *process, gint status, gpointer user_data)
Flags: Run Last
Since: 1.1.5