Given a process which accept command line input as below
$ ./app
> init
initialized.
> start
started.
> stop
stopped.
Is it possible to write a shell script or another C program which trigger ./app, and inject command sequentially? Let say the script-to-be-written will inject string “init”, and wait for reply string “initialized.”, then inject “start”, and wait for reply “started.”, and so on.
The Unix
expecttool has been created for exactly this scenario. You provide a script where you state the expected string (likeinitialized) and declare the appropriate action following that string. Of course there is also some kind of “START” thing.See http://en.wikipedia.org/wiki/Expect for examples.