ibm-information-center/dist/eclipse/plugins/i5OS.ic.rzahz_5.4.0.1/qzshsyst.htm

225 lines
5.8 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<html>
<head>
<meta name="generator" content="HTML Tidy, see www.w3.org">
<meta http-equiv="Content-Type" content=
"text/html; charset=utf-8">
<title>Qp0zSystem() - Run a QSH Command</title>
<LINK rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</HEAD>
<body bgcolor="#FFFFFF">
<!-- Java sync-link -->
<SCRIPT LANGUAGE="Javascript" SRC="../rzahg/synch.js" TYPE="text/javascript"></SCRIPT>
<h2>QzshSystem() - Run a QSH Command</h2>
<table border cellpadding="10" width="100%">
<tr>
<td>Syntax
<pre>
#include &lt;qshell.h&gt;
int QzshSystem( const char <em>*command</em> );
</pre>
<p><br>
Threadsafe: Yes</p>
</td>
</tr>
</table>
<p>The <strong>QzshSystem()</strong> function runs the specified
shell command by spawning a child process and invoking <strong>
qsh</strong> in the child process. <strong>qsh</strong> interprets
and runs <em>command</em> and then exits.</p>
<p>The <strong>QzshSystem()</strong> function returns when the
child process has ended. While the <strong>QzshSystem()</strong>
function is waiting for the child process to end, it ignores the
SIGQUIT and SIGINT signals, and blocks the SIGCHLD signal. The
<strong>QzshSystem()</strong> function does not affect the status
information of any other child processes started by the calling
process.
<p><strong>Parameters</strong></p>
<p><em>*command</em><br>
(Input) Pointer to null-terminated string that contains the shell
command to run.
<p><strong>Authorities</strong></p>
<table border cellpadding="5" width="100%">
<tr>
<th>Object Referred To</th>
<th>Authority Required</th>
<th>errno</th>
</tr>
<tr>
<td width="60%">Each directory in the path name preceding the executable
file</td>
<td width="20%">*X</td>
<td width="20%">EACCES</td>
</tr>
<tr>
<td>Executable file</td>
<td>*X</td>
<td>EACCES</td>
</tr>
<tr>
<td>If executable file is a shell script</td>
<td>*RX</td>
<td>EACCES</td>
</tr>
</table>
<p><strong>Return value</strong></p>
<dl>
<dt><strong>value</strong></dt>
<dd><strong>QzshSystem()</strong> was successful. The return value
is the status returned from the <strong>waitpid()</strong>
function. An application can use the macros provided in the
sys/wait.h header file to interpret the status information from the
child process. The return value can be a negative number.<p></dd>
<dt><strong>-1</strong></dt>
<dd><strong>QzshSystem()</strong> was not successful. The <em>
errno</em> value is set to indicate the error.<p></dd>
</dl>
<p><strong>Error conditions</strong></p>
<p>If <strong>QzshSystem()</strong> is not successful, <i>errno</i>
typically indicates one of the following errors. Under some
conditions, <i>errno</i> could indicate an error other than those
listed here.</p>
<dl>
<dt><strong>[EACCES]</strong></dt>
<dd>Permission denied.<p></dd>
<dd>An attempt was made to access an object in a way forbidden by
its object access permissions.<p></dd>
<dd>The thread does not have access to the specified file,
directory, component, or path.<p></dd>
<dt><strong>[ECHILD]</strong></dt>
<dd>Calling process has no remaining child processes on which wait
operation can be performed.<p></dd>
<dt><strong>[EFAULT]</strong></dt>
<dd>The address used for an argument is not correct.<p></dd>
<dd>In attempting to use an argument in a call, the system detected
an address that is not valid.<p></dd>
<dd>While attempting to access a parameter passed to this function,
the system detected an address that is not valid.<p></dd>
<dt><strong>[EINVAL]</strong></dt>
<dd>The value specified for the argument is not correct.<p></dd>
<dd>A function was passed incorrect argument values, or an
operation was attempted on an object and the operation specified is
not supported for that type of object.<p></dd>
<dt><strong>[ENOMEM]</strong></dt>
<dd>Storage allocation request failed.<p></dd>
<dd>A function needed to allocate storage, but no storage is
available.<p></dd>
<dd>There is not enough memory to perform the requested
function.<p></dd>
<dt><strong>[ENOSYSRSC]</strong></dt>
<dd>System resources not available to complete request.<p></dd>
<dt><strong>[EUNKNOWN]</strong></dt>
<dd>Unknown system state.<p></dd>
<dd>The operation failed because of an unknown system state. See
any messages in the job log and correct any errors that are
indicated. Then try the operation again.<p></dd>
</dl>
<p><strong>Related information</strong></p>
<ul>
<li><a href="qzshchkc.htm">QzshCheckShellCommand()
- Find QSH command</a></li>
<li><a href="../apis/spawn.htm">spawn() - Spawn Process</a></li>
<li><a href="../apis/waitpid.htm">waitpid() - Wait for Specific Child
Process</a></li>
</ul>
<p><strong>Example: Using the QzshSystem() and QzshCheckShellCommand()
functions</strong></p>
<p>The following example shows how to use the <strong>
QzshSystem()</strong> and <strong>QzshCheckShellCommand()</strong>
functions.</p>
<pre>
#include &lt;stdio.h&gt;
#include &lt;qshell.h&gt;
#include &lt;sys/wait.h&gt;
#include &lt;errno.h&gt;
int main(int argc, char *argv[])
{
int status;
char *command = "ls";
/* Verify the user has access to the specified command. */
if (QzshCheckShellCommand(command, NULL) == 0) {
/* Run the specified command. */
status = QzshSystem(command);
if (WIFEXITED(status)) {
printf("Command %s completed with exit status %d.\n",
command, WEXITSTATUS(status));
}
else if (WIFSIGNALED(status)) {
printf("Command %s ended with signal %d.\n",
command, WTERMSIG(status));
}
else if (WIFEXCEPTION(status)) {
printf("Command %s ended with exception.\n", command);
}
}
else
printf("Error %d finding command %s\n", errno, command);
return(0);
}
</pre>
<strong>Output</strong>
<pre>
Command ls completed with exit status 0.
</pre>
</body>
</html>