How do you start Unix screen command with a command?

杀马特。学长 韩版系。学妹 提交于 2019-11-28 17:04:06

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:

screen -t "autotest" 2 bash -c 'cd ~/project/contactdb ; autotest'

Spawns two shells, but life will probably go on.

sodamnmad

Try this:

$ screen -S 'tailf messages' -d -m tailf /var/log/messages

Then later you can do:

$ screen -ls
1234.tailf messages

Followed by:

$screen -r 1234

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:


screen -t "shell_0"  1

# create the following screen in the desired dir, instead of cd-ing afterwards :)
chdir ~/project/contactdb
screen -t "autotest" 2

# (without this sometimes screens fail to start correctly for me)
sleep 5

# paste some text into screen number 2:
select 2
stuff "autotest\012"

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.

screen -t zsh 1
screen -t emacs 2 emacs -nw
screen -t mutt 3 mutt
monitor on
screen -t mc 4 mc -s
screen -t elinks 4 elinks

Here's how I'd do it.

screen -t shell_0
chdir ~/project/contactdb
screen -t autotest autotest

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 the autotest command.

Window number (n) is optional, I generally omit it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!