#include <miniexpect.h>
mexp_h *h;
- h = mexp_spawnl ("ssh", "ssh", "host");
+ h = mexp_spawnl ("ssh", "ssh", "host", NULL);
switch (mexp_expect (h, regexps, ovector, ovecsize)) {
...
}
=head1 SPAWNING THE SUBPROCESS
-There are two calls for creating a subprocess:
+There are four calls for creating a subprocess:
B<mexp_h *mexp_spawnl (const char *file, const char *arg, ...);>
This creates a subprocess running the external program C<file> (the
current C<$PATH> is searched unless you give an absolute path).
-C<arg, ...> are the arguments to the program. Usually the first
-argument should be the name of the program.
+C<arg, ...> are the arguments to the program. You should terminate
+the list of arguments with C<NULL>. Usually the first argument should
+be the name of the program.
The return value is a handle (see next section).
For example, to run an ssh subprocess you could do:
- h = mexp_spawnl ("ssh", "ssh", "-l", "root", "host");
+ h = mexp_spawnl ("ssh", "ssh", "-l", "root", "host", NULL);
or to run a particular ssh binary:
- h = mexp_spawnl ("/usr/local/bin/ssh", "ssh", "-l", "root", "host");
+ h = mexp_spawnl ("/usr/local/bin/ssh", "ssh", "-l", "root", "host", NULL);
An alternative to C<mexp_spawnl> is:
This is the same as C<mexp_spawnl> except that you pass the arguments
in a NULL-terminated array.
+There are also two versions of the above calls which take flags:
+
+B<mexp_h *mexp_spawnlf (unsigned flags, const char *file, const char *arg, ...);>
+
+B<mexp_h *mexp_spawnvf (unsigned flags, const char *file, char **argv);>
+
+The flags may contain the following values, logically ORed together:
+
+=over 4
+
+=item B<MEXP_SPAWN_KEEP_SIGNALS>
+
+Do not reset signal handlers to C<SIG_DFL> in the subprocess.
+
+=item B<MEXP_SPAWN_KEEP_FDS>
+
+Do not close file descriptors E<ge> 3 in the subprocess.
+
+=item B<MEXP_SPAWN_COOKED_MODE> or B<MEXP_SPAWN_RAW_MODE>
+
+Configure the pty in cooked mode or raw mode. Raw mode is the
+default.
+
+=back
+
=head1 HANDLES
After spawning a subprocess, you get back a handle which is a pointer
B<void mexp_set_timeout (mexp_h *h, int secs);>
-Get and set the timeout used by C<mexp_expect> [see below]. The
+Get or set the timeout used by C<mexp_expect> [see below]. The
resolution is milliseconds (1/1000th of a second). Set this before
calling C<mexp_expect>. Passing -1 to either of the C<set_> methods
means no timeout. The default setting is 60000 milliseconds (60
=back
+B<int mexp_send_interrupt (mexp_h *h);>
+
+Send the interrupt character (C<^C>, Ctrl-C, C<\003>). This is like
+pressing C<^C> - the subprocess (or remote process, if using C<ssh>)
+is gracefully killed.
+
+Note this only works if the pty is in cooked mode
+(ie. C<MEXP_SPAWN_COOKED_MODE> was passed to C<mexp_spawnlf> or
+C<mexp_spawnvf>). In raw mode, all characters are passed through
+without any special interpretation.
+
=head1 SOURCE
Source is available from: