如何用命令启动 Unix screen 命令?
根据Unix“screen”命令的文档,您可以配置它在 .screenrc 中以一堆默认屏幕开始,每个屏幕运行您指定的命令。
这是我的配置:
# Default screens
screen -t "shell_0" 1
screen -t "autotest" 2 cd ~/project/contactdb ; autotest
它不会运行自动测试命令。 当我启动 screen
时,我尝试运行 autotest
的窗口会立即关闭。
我也尝试过......
screen -t "autotest" 2 cd ~/project/contactdb
同样的结果。
我也尝试过...
screen -t "autotest" 2 ls
那里也有同样的结果。
让它在启动时在给定屏幕中运行命令的秘诀是什么?
According to the docs for the Unix "screen" command, you can configure it in .screenrc to start with a bunch of default screens, each running a command that you specify.
Here's my cofig:
# Default screens
screen -t "shell_0" 1
screen -t "autotest" 2 cd ~/project/contactdb ; autotest
It will not run the autotest command. That window where I'm trying to run autotest
just closes instantly when I start screen
.
I also tried it with just...
screen -t "autotest" 2 cd ~/project/contactdb
Same result.
I also tried...
screen -t "autotest" 2 ls
Same result there too.
What's the secret to getting it to run a command in a given screen on startup?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
你的程序正在运行(好吧,除了 cd),只是它是在没有父 shell 的情况下运行的,所以一旦它完成,它就会退出,你就完成了。
你可以这样做:
产生两个壳,但生活可能会继续下去。
Your program is being run (well, except the cd), it's just that it's being run without a parent shell, so as soon as it completes, it exits and you're done.
You could do:
Spawns two shells, but life will probably go on.
试试这个:
然后你可以这样做:
然后是:
Try this:
Then later you can do:
Followed by:
这可能会有所帮助,但可能并不完全是您想要的。
将“zombie az”或“defzombie az”作为 .screenrc 的第一行。 “az”可以是您想要的任意 2 个键。 现在,当屏幕应该关闭时(例如,命令执行完毕),它实际上不会关闭; 点击“a”将关闭它,点击“z”将重新执行附加到该屏幕的命令。
我在屏幕用户手册中找到了这一点。
This might help but may not be entirely what you want.
Put "zombie az" or "defzombie az" as the first line of your .screenrc. "az" can be whatever 2 keys you'd like. Now, when a screen ought to close (command finished executing, for instance), it won't actually close; hitting 'a' will close it, hitting 'z' will re-execute the command attached to that screen.
I found that at the screen user's manual.
您还可以将字符“填充”到屏幕中,就像您键入它们一样。
以下是您如何使用示例来做到这一点:
You can also "stuff" characters into the screen as if you had typed them.
Here's how you can do that with your example:
这是我的样子。 看起来效果很好。 我认为括号可能会导致问题,或者如果命令“自动测试”不存在,屏幕将不会打开窗口。
Here's how mine looks. It seems to work fine. I think either the parenthesis might be causing the problem or screen will not open a window if the command "autotest" does not exist.
我就是这样做的。
上述内容似乎是通过屏幕按程序进行评估的。 首先,我们建立一个标题为
shell_0
的新屏幕。 由于我们没有提供其他选项,因此当前工作目录将是父 shell 或用户主目录的目录。 然后,我们将新屏幕的默认目录设置为~/project/contactdb
。 接下来,我们建立一个运行autotest
命令的新屏幕。窗口号(
n
)是可选的,我通常省略它。Here's how I'd do it.
The above appears to be evaluated procedurally by screen. First we establish a new screen with the title
shell_0
. Since we gave no other options, current working directory will be that of the parent shell or the user's home directory. We then set the default directory for new screens to~/project/contactdb
. Next, we establish a new screen running theautotest
command.Window number (
n
) is optional, I generally omit it.