【问题标题】:i need a way to input text into an already running program in terminal (linux)我需要一种将文本输入终端(linux)中已经运行的程序的方法
【发布时间】:2020-08-02 08:47:31
【问题描述】:

(架构 Linux) 基本上我有一个程序在终端中运行,我想要一个脚本在几个小时后输入一些命令。

我试过了:

  • ./program < inputfile ...问题在于它会立即传递命令,我需要等待或睡眠功能。
  • ./bashscript | ./program ... 这做了更多我想要的事情,只是那时我无法自己将任何命令输入到程序中。所以这也是不行的。

更新:更多信息..该程序是我的世界基岩服务器,我要传递的命令是“停止”,这将停止程序。

有什么建议吗?

【问题讨论】:

    标签: linux terminal automation


    【解决方案1】:

    通过修改程序,你可以使用read,几个选项。

    1) 停止程序(*) 执行:

    while read line; do $line; done < inputfile
    

    2) 在特定时间从输入文件中读取,在this example中有更多解释

    exec 3< /etc/path/to/inputfile #define this in the beginning of program
    
    ... program doing things
    
    read 3 -u a b
    

    (*) 在这两种情况下,更多地了解“程序”是很重要的。

    有了这个,你基本上停止了state,所以需要考虑它是否可以优雅地停止执行它所做的一切(定期运行读取?完成后停止它的状态?),并开始接受其他命令输入?

    【讨论】:

    • 它是一个我的世界基岩服务器,所以停止听起来不是一个好主意。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-05-13
    • 1970-01-01
    • 2010-11-17
    • 2014-02-09
    • 2013-05-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多