1

使用“screen -D -R -S foo”,可以附加到名为“foo”的现有会话,或者如果所述会话不存在,则创建它。

如何获取包含屏幕命令的文件?

我认为这会起作用:

screen -D -R -S foo -X source file

不幸的是,这条消息失败了:

No screen session found.

编辑:正如 zebediah49 在评论中指出的那样,我错误地遗漏了“-X 源文件”中的“源”。现在更新了。

4

1 回答 1

1

好的,仔细阅读我注意到的手册页:

   -X   Send the specified command to a running screen  session.  You  can
        use  the  -d or -r option to tell screen to look only for attached
        or detached screen sessions. Note that this command  doesn't  work
        if the session is password protected.

运行屏幕会话。换句话说,我不相信你可以像那样只用一个命令就可以做到你想要的。但是,您可以

  1. 如果窗口不存在则创建窗口
  2. 将命令发送到窗口
  3. 连接到窗口:

    NL=$'\n' NAME=foo 屏幕 -ls | grep "$NAME" || screen -d -m -S "$NAME" screen -r "$NAME" -X stuff "源文件$NL" screen -D -R -S "$NAME"

(澄清 -X 的工作原理,从发送命令到 GNU 屏幕

于 2012-10-26T17:11:00.717 回答