QzshSystem() - Run a QSH Command

Syntax
  #include <qshell.h>

  int QzshSystem( const char *command );


Threadsafe: Yes

The QzshSystem() function runs the specified shell command by spawning a child process and invoking qsh in the child process. qsh interprets and runs command and then exits.

The QzshSystem() function returns when the child process has ended. While the QzshSystem() function is waiting for the child process to end, it ignores the SIGQUIT and SIGINT signals, and blocks the SIGCHLD signal. The QzshSystem() function does not affect the status information of any other child processes started by the calling process.

Parameters

*command
(Input) Pointer to null-terminated string that contains the shell command to run.

Authorities

Object Referred To Authority Required errno
Each directory in the path name preceding the executable file *X EACCES
Executable file *X EACCES
If executable file is a shell script *RX EACCES

Return value

value
QzshSystem() was successful. The return value is the status returned from the waitpid() 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.

-1
QzshSystem() was not successful. The errno value is set to indicate the error.

Error conditions

If QzshSystem() is not successful, errno typically indicates one of the following errors. Under some conditions, errno could indicate an error other than those listed here.

[EACCES]
Permission denied.

An attempt was made to access an object in a way forbidden by its object access permissions.

The thread does not have access to the specified file, directory, component, or path.

[ECHILD]
Calling process has no remaining child processes on which wait operation can be performed.

[EFAULT]
The address used for an argument is not correct.

In attempting to use an argument in a call, the system detected an address that is not valid.

While attempting to access a parameter passed to this function, the system detected an address that is not valid.

[EINVAL]
The value specified for the argument is not correct.

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.

[ENOMEM]
Storage allocation request failed.

A function needed to allocate storage, but no storage is available.

There is not enough memory to perform the requested function.

[ENOSYSRSC]
System resources not available to complete request.

[EUNKNOWN]
Unknown system state.

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.

Related information

Example: Using the QzshSystem() and QzshCheckShellCommand() functions

The following example shows how to use the QzshSystem() and QzshCheckShellCommand() functions.

#include <stdio.h>
#include <qshell.h>
#include <sys/wait.h>
#include <errno.h>

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);
}

Output
Command ls completed with exit status 0.