Back to home page
Back to previous page

Author: R. Koucha
Last update: 09-Jun-2015

SourceForge.net Logo
Support This Project

Programmed Dialogue with Interactive Programs

(PDIP)



Introduction
Usage
Examples
Download
Installation & build
About the author
Related links


Introduction


PDIP stands for Programmed Dialogue with Interactive Programs. It is  a command line oriented utility looking like a simplified  version  of the famous EXPECT utility. The acronym PDIP itself comes from the first lines of the manual of EXPECT.  Like EXPECT,  it  is a freeware and it interprets a scripting language to dialog with an interactive program as a human operator would do. But it has not all the bells and whistles of EXPECT which is able to interact with multiple programs  at the same time, accept a high level scripting language providing branching and high level control structures or giving back the control to the operator during a session.

PDIP accepts a very simple language on the input to provide basic functions such as:

PDIP has been designed to run under any Linux operating system.

The command to launch along with its options and parameters is passed at the end of the command line. If options are passed to pdip and/or the command, then  the  command  must  be preceded  by  a double hyphen (--). Otherwise the options will be passed to pdip and will trigger errors.


Usage

The command line to launch PDIP looks like:

pdip [ -s cmdfile ] [ -b buffer-size ] [ -d level ] [ -h ] [ -V ] [ -e ] [ -t ] [ -o ] [ -p ]-- command options parameters...


The options are:

-b buffer-size | --bufsz=buffer-size
Size in bytes of the internal I/O buffer (default: 512).

-d | --debug
Set the debug mode. It is helpful to understand why a command script does not  work as expected.

-h | --help

Display the help of the command (subset of this man page).

-s cmdfile | --script=cmdfile
Script of input commands (default stdin). PDIP reads cmdfile or the standard input (default) and accepts the following commands:

#...
# and the following words up to the end of line are ignored (used for comments)

dbg level
Set the debug level to level.  The higher the level, the more traces you get. The value 0 deactivates the debug mode.

timeout x
Set  to  x  seconds the maximum time to wait on each following commands (the value 0 cancels the timeout, this is the default)

recv "w1 w2..."
Wait for a line with the pattern w1 w2...  from the program. The pattern is  regular expression conforming to regex (cf. Section 7 of Linux manual).

send "w1 w2..."
Send  the string w1 w2...  to the program.

print "w1 w2..."
Print the string w1 w2...  onto the standard output.

For both send and print commands, the string may contain control characters with the notation "^character". For example, "^C" means CONTROL C. The following shortcuts are also accepted:

\a Bell
\b Backspace
\t Horizontal tabulation
\n New line
\v Vertical tabulation
\f Form feed
\r Carriage return
\" Double quote
\\ Backslash
\[ Escape
\] Group Separatorroup Separator
\^ ^ character

sig signame
Send the Linux signal signame to the program.  signame is one of: HUP, INT, QUIT, ILL, TRAP, ABRT, BUS, FPE, KILL, USR1, SEGV, USR2, PIPE, ALRM, TERM.

sleep x

Stop activity during x seconds

exit
Terminate PDIP

sh [-s] cmd par...
Launch the cmd par...  shell command (synchronously if -s is specified).

-V | --version
Display the version of the software.

-e | --error
Redirect error output of the controlled program.

-t | --term
Make pdip behave as a simple line mode terminal.

-o | --outstand
Make pdip print unread data from the controlled program at the end of the session.

-p | --propexit
Propagate  the  exit  code of the controlled program to pdip.  This makes pdip exit with the exit code of the controlled program (the exit code is 1 if the controlled program terminates because of a signal). By default, the exit code of pdip is 0 no matter the exit code of the controlled program  unless there is an error internal to pdip.

-R | --backread
Read and store in background incoming data from controlled program even when no 'recv' command is on track. This avoids the blocking of the controlled program on a 'write' system call because of the saturation of the internal pseudo-terminal buffer when pdip is not in a data reception state (i.e. 'recv' command). But this makes pdip allocate dynamic memory to store the pending read data.


Examples

The  following  example  shows  how  to  set up a telnet connection to a given host called ’remote’ on  the  TCP  port  34770 with the login name ’foo’ and password ’bar’.  Since the remote port is specified with an option (-p), it is mandatory to put a  double  hyphen  (--) before  the command to launch. Commands are injected on the standard  input.  We wait for the ’$’ prompt and launch the ls(1) command before disconnecting from the shell via the exit command.

$ pdip -- telnet -p 34770 remote
recv "login"
send "foo\n"   # Login name is ’foo’
recv "Password"
send "bar\n"   # Password is ’bar’
recv "\$ "     # Inhibition of the metacharacter ’$’ with ’\’
send "ls\n"    # Launch the ’ls’ command
recv "\$ "
send "exit\n"  # Exit from the shell
exit           # Exit from PDIP
$

The following example shows how to set up a ftp  connection  to  a  given  host  called ’remote’ with the login name ’foo’ and password ’bar’.  Commands are injected on the standard input. We wait for the ’ftp>’ prompt at the beginning of  the  line  and  launch  the ’help’ command before disconnecting from ftp with the ’quit’ command.

$ pdip ftp remote
recv "Name"
send "foo\n"    # Login name is ’foo’
recv "Password"
send "bar\n"    # Password is ’bar’
recv "^ftp> "   # Prompt at beginning of line
send "help\n"   # Launch the ’help’ command
recv "^ftp> "
send "quit\n"   # Terminate FTP
exit            # Exit from PDIP
$

The  following example shows how to interact with the program bc which does not display any prompt. We use the metacharacter ’$’ to synchronize on end of  lines.  Two  operations are launched ’3+4’ and ’6*8’. Then we quit bc.

$ pdip bc
recv "warranty"  # Near the end of the startup banner
recv "$"         # End of last line of the banner
send "3+4\n"
recv "$"         # Receive the end of line of the echo
recv "$"         # Receive the end of line of the result
send "6*8\n"
recv "$"
recv "$"
send "quit\n"   # Terminate BC
exit            # Exit from PDIP
$

The following example shows how to set up a telnet(1) connection  to  a  given  host  called ’remote’  with  the login name ’foo’ and password ’bar’.  Commands are injected on the standard  input.  With  a  regular  expression,  we  wait   for   the   prompt   of   the   form "xxxx-<login_name>-pathname>  "  or  "xxxx-<login_name>-pathname>"  at  the beginning of the line.  Then we launch the ’ls -l’ command  before  disconnecting  from  telnet(1)  with  the ’exit’ command.

$ pdip telnet remote
recv "login:"
send "foo\n"                  # Login name is ’foo’
recv "Password:"
send "bar\n"                  # Password is ’bar’
recv "^(.)+-foo-(.)+(>|> )$"  # Prompt at beginning of line
send "ls -l\n"                # Launch the ’ls -l’ command
recv "^(.)+-foo-(.)+(>|> )$"
send "exit\n"                 # Terminate telnet
exit                          # Exit from PDIP
$


Download


PDIP can be downloaded from this page in one of the following three ways:

Installation & build

PDIP can be installed in three ways:

           1. Installation from the sources
           2. Installation from the DEB binary package
           3. Installation from the RPM binary package

From the sources, you can generate a DEB or binary package:
           4. Generation of a DEB binary package
           5. Generation of a RPM binary package

You can generate a zipped tar file of the sources:
           6. Generation of a zipped tar file


1. Installation from the sources

The installation from the sources supposes that cmake is installed on your Linux system.
Unpack the tar compressed file pdip-xxx.tgz into a directory. This will create a sub-directory called pdip-xxx with the source files of the program:

$ tar xvfz pdip-xxx.tgz

Go into the newly created directory:

$ cd pdip-xxx

Make sure the file 'pdip_install.sh' has the execute permission:

$ chmod +x pdip_install.sh

Launch the script 'pdip_install.sh' to get the help:

$ ./pdip_install.sh -h

Usage: pdip_install.sh [-d install_root_dir] [-P DEB | RPM] [-B] [-I] [-A] [-h]

             -d : Installation directory (default: /usr/local)
             -P : Generate a DEB or RPM package
             -B : Build the software
             -I : Install the software
             -A : Generate an archive of the software (sources)
             -h : this help

Under root identity, launch the installation by passing '-I' and optionnaly '-d' to specify an installation directory different than '/usr/local':

For example, for an installation in '/usr/local', type:

$ sudo ./pdip_install.sh -I

For an installation in '/usr', type;

$ sudo ./pdip_install.sh -I -d /usr

If your PATH variable is correctly set, PDIP help can be displayed:

$ pdip --help
[...]

If your MANPATH variable is correctly set, PDIP's online manual can be displayed:

$ man pdip
[...]

2. Installation of the binaries from the DEB package

The files are installed in via the command:

$ sudo dpkg -i pdip-xxx.deb

3. Installation of the binaries from the RPM package

The files are installed via the command:

$ sudo rpm -i pdip-xxx.rpm

4. Generation of a DEB binary package

The installation from the sources supposes that cmake is installed on your Linux system
Unpack the tar compressed file pdip-xxx.tgz into a directory. This will create a sub-directory called 'pdip-xxx' with the source files of the program:

$ tar xvfz pdip-xxx.tgz

Go into the newly created directory:

$ cd pdip-xxx

Make sure the file 'pdip_install.sh' has the execute permission:

$ chmod +x pdip_install.sh

Launch the script 'pdip_install.sh' to get the help:

$ ./pdip_install.sh -h

Usage: pdip_install.sh [-d install_root_dir] [-P DEB | RPM] [-B] [-I] [-A] [-h]

             -d : Installation directory (default: /usr/local)
             -P : Generate a DEB or RPM package
             -B : Build the software
             -I : Install the software
             -A : Generate an archive of the software (sources)
             -h : this help

Under root identity, launch the installation by passing '-P DEB' and optionnaly '-d' to specify an installation directory different than '/usr/local':

For example, for a package which will be installed in '/usr/local', type:

$ sudo ./pdip_install.sh -P DEB

For an installation in '/usr', type;

$ sudo ./pdip_install.sh -P DEB -d /usr

5. Generation of a RPM binary package

The installation from the sources supposes that cmake is installed on your Linux system.
Unpack the tar compressed file pdip-xxx.tgz into a directory. This will create a sub-directory called 'pdip-xxx' with the source files of the program:

$ tar xvfz pdip-xxx.tgz

Go into the newly created directory:

$ cd pdip-xxx

Make sure the file 'pdip_install.sh' has the execute permission:

$ chmod +x pdip_install.sh

Launch the script 'pdip_install.sh' to get the help:

$ ./pdip_install.sh -h

Usage: pdip_install.sh [-d install_root_dir] [-P DEB | RPM] [-B] [-I] [-A] [-h]

             -d : Installation directory (default: /usr/local)
             -P : Generate a DEB or RPM package
             -B : Build the software
             -I : Install the software
             -A : Generate an archive of the software (sources)
             -h : this help

Under root identity, launch the installation by passing '-P RPM' and optionnaly '-d' to specify an installation directory different than '/usr/local':

For example, for a package which will be installed in '/usr/local', type:

$ sudo ./pdip_install.sh -P RPM

For an installation in '/usr', type;

$ sudo ./pdip_install.sh -P RPM -d /usr

6. Generation of a zipped tar file

The installation from the sources supposes that cmake is installed on your Linux system.
Unpack the tar compressed file pdip-xxx.tgz into a directory. This will create a sub-directory called 'pdip-xxx' with the source files of the program:

$ tar xvfz pdip-xxx.tgz

Go into the newly created directory:

$ cd pdip-xxx

Make sure the file 'pdip_install.sh' has the execute permission:

$ chmod +x pdip_install.sh

Launch the script 'pdip_install.sh' to get the help:

$ ./pdip_install.sh -h

Usage: pdip_install.sh [-d install_root_dir] [-P DEB | RPM] [-B] [-I] [-A] [-h]

             -d : Installation directory (default: /usr/local)
             -P : Generate a DEB or RPM package
             -B : Build the software
             -I : Install the software
             -A : Generate an archive of the software (sources)
             -h : this help

Under root identity, launch the installation by passing '-A':

$ sudo ./pdip_install.sh -A



About the author

The author is an engineer in computer sciences located in France. He is glad to graciously offer this simple utility under the GPL open source license. He can be contacted at "rachid dot koucha at free dot fr" or you can have a look at his WEB home page.


Related links



Back to home page
Back to previous page