简体   繁体   English

命令行界面和过程控制

[英]Command Line Interface & Process Control

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? 是否可以编写触发./app的Shell脚本或其他C程序,并依次注入命令? 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. 假设要编写的脚本将注入字符串“ init”,等待回复字符串“ initialized。”,然后注入“ start”,等待回复“ started。”,依此类推。

The Unix expect tool has been created for exactly this scenario. 正是针对这种情况创建了Unix expect工具。 You provide a script where you state the expected string (like initialized ) and declare the appropriate action following that string. 您可以提供一个脚本,在其中声明所需的字符串(如initialized ),并在该字符串之后声明适当的操作。 Of course there is also some kind of "START" thing. 当然,还有某种“开始”的事情。

See http://en.wikipedia.org/wiki/Expect for examples. 有关示例,请参见http://en.wikipedia.org/wiki/Expect

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM