Function

GLibshell_parse_argv

Declaration

gboolean
g_shell_parse_argv (
  const gchar* command_line,
  gint* argcp,
  gchar*** argvp,
  GError** error
)

Description

Parses a command line into an argument vector, in much the same way the shell would, but without many of the expansions the shell would perform (variable expansion, globs, operators, filename expansion, etc. are not supported).

The results are defined to be the same as those you would get from a UNIX98 /bin/sh, as long as the input contains none of the unsupported shell expansions. If the input does contain such expansions, they are passed through literally.

Possible errors are those from the G_SHELL_ERROR domain.

In particular, if command_line is an empty string (or a string containing only whitespace), G_SHELL_ERROR_EMPTY_STRING will be returned. It’s guaranteed that argvp will be a non-empty array if this function returns successfully.

Free the returned vector with g_strfreev().

Parameters

command_line

Type: const gchar*

Command line to parse.

The data is owned by the caller of the function.
The value is a file system path, using the OS encoding.
argcp

Type: gint*

Return location for number of args.

The argument will be set by the function.
The argument can be NULL.
argvp

Type: An array of filename

return location for array of args.

The argument will be set by the function.
The argument can be NULL.
The array must be NULL-terminated.
The length of the array is specified in the argcp argument.
The called function takes ownership of the data, and is responsible for freeing it.
Each element is a file system path, using the OS encoding.
error

Type: GError **

The return location for a recoverable error.

The argument can be NULL.
If the return location is not NULL, then you must initialize it to a NULL GError*.
The argument will left initialized to NULL by the function if there are no errors.
In case of error, the argument will be set to a newly allocated GError; the caller will take ownership of the data, and be responsible for freeing it.

Return value

Type: gboolean

TRUE on success, FALSE if error set.