Wraps an interactive CLI application to translate signals into text for the application's stdin
Last updated 4 years ago by ahelper .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install cliwrapper 
SYNC missed versions from official npm registry.


NPM Version Build Status

Want to run some services that only run with an interactive CLI but don't want to control them manually? Does the application not shutdown cleanly when terminated? You should wrap it!


Primary supported platform is Linux. Windows support is untested.

For global usage, ensure you have Node.js and NPM and run the following as root:

# npm install -g cliwrapper


There's no time to explain, here's an example!

# Wait for server init
WAITFOR Listening on port
# Announce it started
TYPE say Server started!\n

# Hit enter a few times in case some command is being typed
SENDKEY Enter Enter Enter
TYPE say Server stopping in 5 seconds!\n
# Wait 5 seconds
# Exit safely
TYPE exit\n

cliwrapper --tty --start=start --signal=SIGTERM,sigterm -- some-cli-server

This is a quick example was based on running the Terraria dedicated server. Keep reading for documentation on the wrapper scripts and how to run CLIWrapper!


Usage: cliwrapper [--tty] [--start=filename] [--signal=name,filename] -- <command> [arguments...]

  --start     Runs a script on program start
  --signal    Runs a script upon receiving a signal   [array][default: []]
  -h, --help  Show help                               [boolean]

NOTE: Send signals to the wrapper, not to the wrapper's child!

Script Documentation

CLIWrapper provides a simple scripting language to interact with applications. Scripts run in response to certain events, such as application start or signals received.

The command is an uppercase keyword followed by exactly 1 space then one or more arguments.

SLEEP [num seconds]

Sleeps for the specified number of seconds. The value represents the floating point number of seconds to sleep for with no greater than millisecond accuracy (see setTimeout for specific timing restrictions).

Example, sleeping for 250ms:

SLEEP 0.25

TYPE [escaped text...]

Sends the text to the wrapped process's stdin. The text uses escape sequences as-per C89's allowed escape sequences ( Character constants). Here's a list of those escape sequences for reference:

Sequence Value
\a 0x07
\b 0x08
\f 0x0C
\n 0x0A
\r 0x0D
\t 0x09
\v 0x0B
' 0x27
" 0x22
? 0x2F
\\ \
\xnn 0xnn
\ooo 0ooo

(nn is a 2 digit hexadecimal value, ooo is a 1 to 3 digit octal value)


# Sends some text
TYPE some text
# Sends a command followed by a newline
TYPE save\n
# Sends a space (See SENDKEY for things like this!)

A word of caution, trailing/leading spaces are part of the escaped text. In the 3rd example, TYPE followed by 2 spaces will treat the second space as the string to send. Be careful of editors that trim trailing whitespace. See SENDKEY to be safe.

SENDKEY [key ...]

Writes characters to the wrapped process's stdin. The characters are generated from a list of space-delimited key names. The following keys are recognized (case-sensative):

  • Enter
  • Esc
  • Escape
  • Up
  • Down
  • Left
  • Right
  • Del
  • Delete
  • Backspace
  • Space
  • Tab
  • Ctrl_(A through Z, [, , ], ~, ?)
  • Ctrl_Space

WAITFOR [escaped text...]

Waits until the process outputs text on either stdout or stderr. Performs an exact match against the escaped string (see TYPE for the escape sequences allowed).

Current Tags

  • 1.0.1                                ...           latest (4 years ago)

2 Versions

  • 1.0.1                                ...           4 years ago
  • 1.0.0                                ...           4 years ago
Maintainers (1)
Today 0
This Week 0
This Month 1
Last Day 0
Last Week 0
Last Month 1
Dependencies (8)
Dev Dependencies (0)
Dependents (0)

Copyright 2014 - 2017 © |