rexec() — Execute commands one at a time on a remote host

Standards

Standards / Extensions C or C++ Dependencies
z/OS® UNIX both

POSIX(ON)

Format

#include <rexec.h>

int rexec(char **Host, int Port, char *User, char *Password,
          char *Command, int *ErrFileDescParam)

General description

The rexec (remote execution) subroutine allows the calling process to execute commands on a remote host. If the rexec connection succeeds, a socket in the Internet domain of type SOCK_STREAM is returned to the calling process and is given to the remote command as standard input and standard output.

Host contains the name of a remote host that is listed in the /etc/hosts file or /etc/resolv.config file. If the name of the host is not found in either file, the rexec fails.

Port specifies the well-known Defense Advanced Research Projects Agency (DARPA) Internet port to use for the connection. A pointer to the structure that contains the necessary port can be obtained by issuing the following library call: getservbyname("exec","tcp").

User and Password points to a user ID and password valid at the host. Password phrases are not supported.

Command points to the name of the command to be executed at the remote host.

ErrFileDescParam specifies one of the following values:
  • Not 0 (zero) = an auxiliary channel to a control process is set up, and a descriptor for it is placed in the ErrFileDescParam parameter. The control process provides diagnostic output from the remote command on this channel and also accepts bytes as signal numbers to be forwarded to the process group of the command. This diagnostic information does not include remote authorization failure, since this connection is set up after authorization has been verified.
  • 0 (zero) = the standard error of the remote command is the same as standard output, and no provision is made for sending arbitrary signals to the remote process. In this case, however, it may be possible to send out-of-band data to the remote command.

This function is supported only in a POSIX program.

Note: The rexec() function has a dependency on the level of the Enhanced ASCII Extensions. See Enhanced ASCII support for details.

Returned value

If rexec() is successful, the system returns a socket to the remote command.

If rexec() is unsuccessful, the system returns a -1 indicating that the specified host name does not exist.

Related information