外部コマンド(非推奨)

外部コマンド(非推奨) — 外部コマンドを使うための便利API(非推奨)

Functions

プロパティ

gpointer command Read / Write

シグナル

Types and Values

オブジェクト階層

    GObject
    ╰── GCutEgg

説明

GCutEggは外部コマンドの実行・通信・終了をカプセル化します。GCutEggはエラーをGErrorとして報告します。エラーはgcut_assert_error()を使うことにより簡単に検証できます。

外部コマンドはgcut_egg_new()gcut_egg_new_strings()などのようなコンストラクタで指定します。この時点では外部コマンドは実行されません。gcut_egg_hatch()で指定された外部コマンドが実行されます。

Standard/Error outputs of external command are passed by “output-received”/“error-received” signals or GIOChannel returned by gcut_egg_get_output()/gcut_egg_get_error(). gcut_egg_write() writes a chunk to standard input of external command.

外部コマンドの終了を待つためにはgcut_egg_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 GCutEgg *egg;

void
cut_setup (void)
{
    output_string = g_string_new(NULL);
    egg = NULL;
}

void
cut_teardown (void)
{
    if (output_string)
        g_string_free(output_string, TRUE);
    if (egg)
        g_object_unref(egg);
}

static void
cb_output_received (GCutEgg *egg, const gchar *chunk, gsize size,
                    gpointer user_data)
{
    g_string_append_len(output_string, chunk, size);
}

void
test_echo (void)
{
    GError *error = NULL;

    egg = gcut_egg_new("echo", "XXX", NULL);
    g_signal_connect(egg, "output-received",
                     G_CALLBACK(cb_output_received), NULL);

    gcut_egg_hatch(egg, &error);
    gcut_assert_error(error);

    gcut_egg_wait(egg, 1000, &error);
    gcut_assert_error(error);
    cut_assert_equal_string("XXX\n", output_string->str);
}

Functions

GCUT_EGG_ERROR

#define GCUT_EGG_ERROR           (gcut_egg_error_quark())

GCUT_EGG_ERRORは非推奨です。新しいコードでは使わないでください。


gcut_egg_error_quark ()

GQuark
gcut_egg_error_quark (void);

gcut_egg_error_quarkは非推奨です。新しいコードでは使わないでください。


gcut_egg_new ()

GCutEgg *
gcut_egg_new (const gchar *command,
              ...);

gcut_egg_new has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_new() instead.

Creates a new GCutEgg object that runs command .

Parameters

command

実行する外部コマンド名。

 

...

commandの引数

 

Returns

新しいGCutEgg

Since: 1.0.6


gcut_egg_new_va_list ()

GCutEgg *
gcut_egg_new_va_list (const gchar *command,
                      va_list args);

gcut_egg_new_va_list has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_new_va_list() instead.

Creates a new GCutEgg object that runs command .

Parameters

command

実行する外部コマンド名。

 

args

commandの引数

 

Returns

新しいGCutEgg

Since: 1.0.6


gcut_egg_new_argv ()

GCutEgg *
gcut_egg_new_argv (gint argc,
                   gchar **argv);

gcut_egg_new_argv has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_new_argv() instead.

Creates a new GCutEgg object that runs command .

Parameters

argc

argvの要素数

 

argv

実行する外部コマンド名とコマンド引数。

 

Returns

新しいGCutEgg

Since: 1.0.6


gcut_egg_new_strings ()

GCutEgg *
gcut_egg_new_strings (const gchar **command);

gcut_egg_new_strings has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_new_strings() instead.

Creates a new GCutEgg object that runs command .

Parameters

command

実行する外部コマンド名とコマンド引数。NULL終端。

 

Returns

新しいGCutEgg

Since: 1.0.6


gcut_egg_new_array ()

GCutEgg *
gcut_egg_new_array (GArray *command);

gcut_egg_new_array has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_new_array() instead.

Creates a new GCutEgg object that runs command .

Parameters

command

実行する外部コマンド名とコマンド引数。GArrayは0終端にして下さい。

 

Returns

新しいGCutEgg

Since: 1.0.6


gcut_egg_set_flags ()

void
gcut_egg_set_flags (GCutEgg *egg,
                    GSpawnFlags flags);

gcut_egg_set_flags has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_set_flags() instead.

外部コマンドを実行するときのflagsを設定します。

Parameters

egg

GCutEgg

 

flags

g_spawn_async_with_pipes()に渡すフラグ。

 

Since: 1.0.6


gcut_egg_get_flags ()

GSpawnFlags
gcut_egg_get_flags (GCutEgg *egg);

gcut_egg_get_flags has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_get_flags() instead.

外部コマンドを実行する時のflagsを取得します。

Parameters

egg

GCutEgg

 

Returns

外部コマンドを実行するときのフラグ。

Since: 1.0.6


gcut_egg_set_env ()

void
gcut_egg_set_env (GCutEgg *egg,
                  const gchar *name,
                  ...);

gcut_egg_set_env has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_set_env() instead.

外部コマンドの環境変数を設定します。

Parameters

egg

GCutEgg

 

name

最初の環境変数名。

 

...

the value of name , followed by name and value pairs. NULL-terminated.

 

Since: 1.0.6


gcut_egg_get_env ()

gchar **
gcut_egg_get_env (GCutEgg *egg);

gcut_egg_get_env has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_get_env() instead.

外部コマンドの環境変数を取得します。

Parameters

egg

GCutEgg

 

Returns

新しく割り当てられたNULL終端の環境変数のリスト("名前1=値1", "名前2=値2", ..., NULL)を返します。必要がなくなったらg_strfreev()で開放してください。

Since: 1.0.6


gcut_egg_hatch ()

gboolean
gcut_egg_hatch (GCutEgg *egg,
                GError **error);

gcut_egg_hatch has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_run() instead.

新しい外部プロセスを実行します。

Parameters

egg

GCutEgg

 

error

エラーを返すアドレスまたはNULL

 

Returns

成功したときはTRUE、そうでない場合はFALSE

Since: 1.0.6


gcut_egg_close ()

void
gcut_egg_close (GCutEgg *egg);

gcut_egg_close has been deprecated since version 1.1.5 and should not be used in newly-written code.

no need to close explicitly on GCutProcess.

実行した外部コマンドのリソースを回収します。破棄されるときに暗黙的に回収されます。

Parameters

egg

GCutEgg

 

Since: 1.0.6


gcut_egg_write ()

gboolean
gcut_egg_write (GCutEgg *egg,
                const gchar *chunk,
                gsize size,
                GError **error);

gcut_egg_write has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_write() instead.

外部プロセスの標準入力にchunkを書き込みます。

Parameters

egg

GCutEgg

 

chunk

書き込むデータ

 

size

chunkのサイズ

 

error

エラーを返すアドレスまたはNULL

 

Returns

成功したときはTRUE、そうでない場合はFALSE

Since: 1.0.6


gcut_egg_get_pid ()

GPid
gcut_egg_get_pid (GCutEgg *egg);

gcut_egg_get_pid has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_get_pid() instead.

実行している外部プロセスのプロセスIDを取得します。外部コマンドが実行されていない場合は0が返ります。

Parameters

egg

GCutEgg

 

Returns

実行中の外部コマンドのプロセスID。実行していない場合は0。

Since: 1.0.6


gcut_egg_wait ()

gint
gcut_egg_wait (GCutEgg *egg,
               guint timeout,
               GError **error);

gcut_egg_wait has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_wait() instead.

実行中の外部プロセスが終了することをtimeoutミリ秒待ちます。外部コマンドがtimeoutミリ秒以内に終了しなかった場合は、GCUT_EGG_ERROR_TIMEOUTエラーが設定され、-1が返ります。外部プロセスが実行されていない場合は、GCUT_EGG_ERROR_NOT_RUNNINGエラーが設定され、-1が返ります。

Parameters

egg

GCutEgg

 

timeout

タイムアウト時間(ミリ秒)

 

error

エラーを返すアドレスまたはNULL

 

Returns

外部プロセスが終了した場合は終了ステータス。そうでない場合は-1。

Since: 1.0.6


gcut_egg_kill ()

void
gcut_egg_kill (GCutEgg *egg,
               gint signal_number);

gcut_egg_kill has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_kill() instead.

外部プロセスにsignal_numberシグナルを送ります。

Parameters

egg

GCutEgg

 

signal_number

外部プロセスに送るシグナル番号。

 

Since: 1.0.6


gcut_egg_get_input ()

GIOChannel *
gcut_egg_get_input (GCutEgg *egg);

gcut_egg_get_input has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_get_input_channel() instead.

外部プロセスの標準入力と結びついたGIOChannelを取得します。

Parameters

egg

GCutEgg

 

Returns

外部プロセスが実行中の場合はGIOChannel。そうでない場合はNULL

Since: 1.0.6


gcut_egg_get_output ()

GIOChannel *
gcut_egg_get_output (GCutEgg *egg);

gcut_egg_get_output has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_get_output_channel() instead.

外部プロセスの標準出力と結びついたGIOChannelを取得します。

Parameters

egg

GCutEgg

 

Returns

外部プロセスが実行中の場合はGIOChannel。そうでない場合はNULL

Since: 1.0.6


gcut_egg_get_error ()

GIOChannel *
gcut_egg_get_error (GCutEgg *egg);

gcut_egg_get_error has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_get_error_channel() instead.

外部プロセスのエラー出力に結びついたGIOChannelを返します。

Parameters

egg

GCutEgg

 

Returns

外部プロセスが実行中の場合はGIOChannel。そうでない場合はNULL

Since: 1.0.6


gcut_egg_get_forced_termination_wait_time ()

guint
gcut_egg_get_forced_termination_wait_time
                               (GCutEgg *egg);

gcut_egg_get_forced_termination_wait_time has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_get_forced_termination_wait_time() instead.

オブジェクトが破棄されるときに行われる外部コマンド強制終了後に待つ時間(ミリ秒)を取得します。

Parameters

egg

GCutEgg

 

Returns

破棄時の強制終了待ちの時間。

Since: 1.0.6


gcut_egg_set_forced_termination_wait_time ()

void
gcut_egg_set_forced_termination_wait_time
                               (GCutEgg *egg,
                                guint timeout);

gcut_egg_set_forced_termination_wait_time has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use gcut_process_set_forced_termination_wait_time() instead.

オブジェクトが破棄されるときに行われる外部コマンド強制終了時に待つ時間(ミリ秒)を設定します。timeoutが0なら外部コマンドの終了を待ちません。デフォルト値は10です。

Parameters

egg

GCutEgg

 

timeout

タイムアウト時間(ミリ秒)

 

Since: 1.0.6

Types and Values

enum GCutEggError

GCutEggError has been deprecated since version 1.1.5 and should not be used in newly-written code.

Use GCutProcessError instead.

GCutEgg関連の操作で返されるエラーコード。

Members

GCUT_EGG_ERROR_COMMAND_LINE

コマンドライン関連のエラー。

 

GCUT_EGG_ERROR_IO_ERROR

入出力エラー。

 

GCUT_EGG_ERROR_ALREADY_RUNNING

外部コマンドはすでに実行されています。

 

GCUT_EGG_ERROR_NOT_RUNNING

外部こもアンドが実行されていません。

 

GCUT_EGG_ERROR_INVALID_OBJECT

不正なGCutEggオブジェクトが渡されました。

 

GCUT_EGG_ERROR_TIMEOUT

タイムアウト。

 

Since: 1.0.6

プロパティ詳細

The “command” property

  “command”                  gpointer

実行する外部コマンド。

Flags: Read / Write

シグナル詳細

The “error” signal

void
user_function (GCutEgg *egg,
               gpointer error,
               gpointer user_data)

Flags: Run Last

Since: 1.0.6


The “error-received” signal

void
user_function (GCutEgg *egg,
               gchar   *chunk,
               guint64  size,
               gpointer user_data)

Flags: Run Last

Since: 1.0.6


The “output-received” signal

void
user_function (GCutEgg *egg,
               gchar   *chunk,
               guint64  size,
               gpointer user_data)

Flags: Run Last

Since: 1.0.6


The “reaped” signal

void
user_function (GCutEgg *egg,
               gint     status,
               gpointer user_data)

Flags: Run Last

Since: 1.0.6