|
edelib
2.0.0
|
Synchronous communication with tty programs. More...
#include <edelib/PtyProcess.h>
Public Types | |
| enum | CheckPidStatus { Error = -1, NotExited = -2, Killed = -3, Crashed = -4 } |
Public Member Functions | |
| PtyProcess () | |
| virtual | ~PtyProcess () |
| int | exec (const char *command, const char **args) |
| char * | read_line (bool block=true) |
| void | write_line (const char *line, bool addNewline=true) |
| void | unread_line (const char *line, bool addNewline=true) |
| void | set_exit_string (char *exit) |
| int | wait_for_child () |
| int | wait_slave () |
| int | enable_local_echo (bool enable=true) |
| void | set_terminal (bool terminal) |
| void | set_erase (bool erase) |
| void | set_environment (const char **env) |
| int | fd () const |
| int | pid () const |
| void | terminate_child () |
Static Public Member Functions | |
| static int | wait_ms (int fd, int ms) |
| static bool | check_pid (pid_t pid) |
| static int | check_pid_exited (pid_t pid) |
Synchronous communication with tty programs.
PtyProcess provides synchronous communication with tty based programs. The communications channel used is a pseudo tty (as opposed to a pipe) This means that programs which require a terminal will work.
| enum CheckPidStatus |
Check process exit status for process pid. On error (no child, no exit), return -1. If child pid has exited, return its exit status, (which may be zero). If child has not exited, return -2.
| PtyProcess | ( | ) |
Empty constructor
| virtual ~PtyProcess | ( | ) | [virtual] |
Clears data
| static bool check_pid | ( | pid_t | pid | ) | [static] |
Basic check for the existence of pid. Returns true iff pid is an extant process, (one you could kill - see man kill(2) for signal 0).
| static int check_pid_exited | ( | pid_t | pid | ) | [static] |
Check process exit status for process pid. On error (no child, no exit), return Error (-1). If child pid has exited, return its exit status, (which may be zero). If child has not exited, return NotExited (-2).
| int enable_local_echo | ( | bool | enable = true | ) |
Enables/disables local echo on the pseudo tty.
| int exec | ( | const char * | command, |
| const char ** | args | ||
| ) |
Forks off and execute a command. The command's standard in and output are connected to the pseudo tty. They are accessible with readLine and writeLine.
| command | The command to execute. |
| args | The arguments to the command. |
| int fd | ( | ) | const [inline] |
Returns the filedescriptor of the process
| int pid | ( | ) | const [inline] |
Returns the pid of the process
| char* read_line | ( | bool | block = true | ) |
Reads a line from the program's standard out. Depending on the block parameter, this call blocks until a single, full line is read.
| block | Block until a full line is read? |
| void set_environment | ( | const char ** | env | ) |
Set additinal environment variables
| void set_erase | ( | bool | erase | ) | [inline] |
Overwrites the password as soon as it is used. Relevant only to some subclasses
| void set_exit_string | ( | char * | exit | ) | [inline] |
Sets the exit string. If a line of program output matches this, waitForChild() will terminate the program and return.
| void set_terminal | ( | bool | terminal | ) | [inline] |
Enables/disables terminal output. Relevant only to some subclasses
| void terminate_child | ( | ) |
Terminate the child process if still running
| void unread_line | ( | const char * | line, |
| bool | addNewline = true |
||
| ) |
Puts back a line of input.
| line | The line to put back. |
| addNewline | Adds a ' ' to the line. |
| int wait_for_child | ( | ) |
Waits for the child to exit
| static int wait_ms | ( | int | fd, |
| int | ms | ||
| ) | [static] |
Wait ms miliseconds (ie. 1/10th of a second is 100ms), using fd as a filedescriptor to wait on. Returns select(2)'s result, which is -1 on error, 0 on timeout, or positive if there is data on one of the selected fd's.
ms must be in the range 0..999 (ie. the maximum wait duration is 999ms, almost one second).
| int wait_slave | ( | ) |
Waits until the pty has cleared the ECHO flag. This is useful when programs write a password prompt before they disable ECHO. Disabling it might flush any input that was written.
| void write_line | ( | const char * | line, |
| bool | addNewline = true |
||
| ) |
Writes a line of text to the program's standard in.
| line | The text to write. |
| addNewline | Adds a ' ' to the line. |
1.7.6.1