Skip to content
/ PlayIO Public

Small tool to perform scripted text console I/O

License

Notifications You must be signed in to change notification settings

rbergen/PlayIO

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

21 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PlayIO

CI

Name

playio - control the interaction with a UN*X text-based application using a very simple scripting language

Synopsis

playio PROGRAM [PROGRAM_OPTIONS]
playio -V

Description

playio executes the indicated PROGRAM, connecting to PROGRAM's standard I/O streams (stdin, and stdout/stderr combined).
Any PROGRAM_OPTIONS that are on the command line after PROGRAM are passed to PROGRAM unchanged.

playio reads a script from standard input that controls how PROGRAM's standard input and output are handled. playio stops when end of file is reached on playio's own standard input. The termination of PROGRAM is then awaited before playio exits.

playio was originally written as a support tool for a specific solution in the github.com/PlummersSoftwareLLC/Primes project, but may serve other purposes as well.

Options

  • -V
    Print the version number of playio to standard output.

Scripting Language

General Format

A playio script consists of one or more lines. Each line contains a one-letter command. All commands accept a textual parameter that consists of whatever else is on the line, including any trailing whitespace. In all cases but one, the parameter itself is optional and the command's behavior depends on whether it is present or not.

Commands

  • f [TEXT]
    Read one line of PROGRAM's standard output or, if TEXT has been specified, read lines from PROGRAM's standard output until one is read that contains TEXT. If no output is available, this command waits until a line becomes available unless end of file occurs.

  • o [TEXT]
    Output TEXT to playio standard output. If no TEXT is specified, output the last line read from PROGRAM's standard output through the use of the f command. If no line was read when the f command was last executed (due to end of file), nothing is printed.

  • p SECONDS
    Pause script processing for SECONDS seconds. Fractional numbers are supported.

  • t [TEXT]
    Output a timestamp to playio standard output. The timestamp is the number of microseconds since epoch. If TEXT is specified, it is output immediately before the actual timestamp.

  • w [TEXT]
    Write TEXT to PROGRAM's standard input, or an empty line if no TEXT is specified.

Exit Status

The exit status of playio is the exit status of PROGRAM in the case of normal execution. If PROGRAM could not be started, the exit status is 127. If any other error occurs, the exit status is 1.

Error Conditions

Simply put, once the pipes between playio and PROGRAM have been setup and PROGRAM is running, playio simply ignores whatever it doesn't understand.
If PROGRAM cannot be found/started, playio will still run the script until its end.
playio can hang when it's waiting for a line of output that contains a specific text, and PROGRAM is waiting for input.

Building

After cloning this repo or downloading playio.c to your UN*X system with GCC and common libraries installed, issue the following command in the repo directory:

$ gcc playio.c -o playio

- Rutger van Bergen - github.com/rbergen