3 cmd \- interface to host operating system commands
20 provides a way to run commands in the underlying operating system's
21 command interpreter of drawterm or when Inferno is running hosted.
22 It serves a three-level directory that is conventionally bound
23 behind the root directory.
24 The top of the hierarchy is a directory
28 file and zero or more numbered directories.
29 Each directory represents a distinct connection to the host's command interpreter.
30 The directory contains five files:
37 used as described below.
40 file reserves a connection: it is equivalent to opening the
42 file of an unused connection directory, creating a new one if necessary.
46 controls a connection.
47 When read, it returns the decimal number
49 of its connection directory.
50 Thus, opening and reading
52 allocates a connection directory and reveals the number of the allocated directory,
53 allowing the other files to be named (eg,
54 .BI /cmd/ n /data\fR).
57 accepts the following textual commands, allowing quoting as interpreted by
61 Run the host command in directory
64 .I "on the host system" .
65 Issue this request before starting the command.
66 By default, commands are run in the Inferno root directory on the host system.
68 .BI "exec " "command args ..."
69 Spawn a host process to run the
71 with arguments as given.
72 The write returns with an error, setting the error string, if anything prevents
74 If write returns successfully, the command has started, and its standard input and
75 output may be accessed through
77 and its error output accessed through
80 If arguments containing white space are quoted (following the conventions of
86 using the host command interpreter's conventions so that
88 sees exactly the same arguments as were written to
92 Kill the host command immediately.
95 Set the device to kill the host command when the
97 file is closed (normally all files must be closed, see below).
99 .BI nice " \fR[\fPn\fR]\fP"
100 Run the host command at less than normal scheduling priority.
101 Issue this request before starting the command.
105 indicates the degree of `niceness' (default: 1).
109 file provides a connection to the input and output of a previously-started
111 It must be opened separately for reading and for writing.
112 When opened for reading, it returns data that the command writes to its standard output; when closed, further writes by the command will receive the host
113 equivalent of `write to closed pipe'.
114 When opened for writing, data written to the file
115 can be read by the command on its standard input; when closed, further reads by
116 the command will see the host equivalent of `end of file'.
117 (Unfortunately there is no way to know when the command needs input.)
121 file provides a similar read-only connection to the error output from the command.
124 file is not opened, the error output will be discarded.
126 Once started, a host command runs until it terminates or until it is killed,
131 requests above, or by closing all
136 files for a connection.
140 file provides a single line giving the status of the connection (not the command), of the form:
142 .BI cmd/ "n opens state wdir arg0"
144 where the fields are separated by white space. The meaning of each field is:
152 The decimal number of open file descriptors for
159 The status of the interface in directory
165 Allocated for use but not yet running a command.
171 Command terminated: status available in the
177 Command completed. Available for reallocation via
183 The command's initial working directory on the host.
186 The host command name (without arguments).
190 file must be opened before starting a command via
192 When read, it blocks until the command terminates.
193 The read then returns with a single status line, to be
198 There are five fields:
199 host process ID (or 0 if unknown);
200 time the command spent in user code in milliseconds (or 0);
201 time spent in system code in milliseconds (or 0);
202 real time in milliseconds (or 0);
203 and a string giving the exit status of the command.
204 The exit status is host-dependent, except that an empty string
205 means success, and a non-empty string contains a diagnostic.
207 .SS "Command execution"
208 In all cases, the command runs in the host operating system's
210 All file names will be interpreted in that space, not Plan9's.
213 refers to the host's file system root, not Plan9's;
214 the effects of mounts and binds will not be visible.
222 returns with an error and sets the error string if
223 a command cannot be started or killed successfully.