Re: screen, detached, stdout

Ben Love <[email protected]>
Newsgroups gmane.comp.gnu.screen.user
Message-ID <[email protected]>
* Nico Schlömer wrote on [2011-02-09 19:07:22 +0100]:
> Hi all,
> 
> I would like to start a series of jobs in the background and log their
> stdout in specific files. The idea is to use screen for this, and I
> went ahead and typed
> 
> $ screen -d -m /path/to/my/exec
> 
> which puts the job nicely in the background. Let's log stdout:
> 
> $ screen -d -m /path/to/my/exec | tee output.log
> 
> Ah, that doesn't work as the it tees the output of `screen` to the
> file. Hmm.. How about
> 
> $ screen -d -m `/path/to/my/exec | tee output.log`
> 
> Now, it directs the output alright, but the session isn't detached anymore.
> 
> I don't quite understand why this happens, so if you guys have a clue
> that'd be great. I'm also looking for a solution to the problem of
> course.

Case 1: Redirects the stdout of screen to tee.  The stdout of screen is
not what you think because its designed to be a terminal multiplexor.

Case 2: Executes the entire backticked expression in a subshell and
passes the stdout of that as the argument to screen.

You didn't try screen -d -m "/path/to/my/exec | tee output", but that
doesn't work either because the entire expression is passed to screen as
one argument, and then screen cannot find an executable with that name.

You might also try escaping the pipe from the current shell, like this:

$ screen -d -m /path/to/my/exec "|" tee output.log

But that doesn't work because the executable itself would get the pipe
as an argument.

This does work:

$ screen -d -m sh -c "/path/to/my/exec | tee output.log"

This works because you tell screen to spawn a shell, and then your argument is
simply the command for the shell.  The shell then correctly parses the
command and does what you intend.

Of course, the other responses about -L are probably simpler to use
anyway.

Ben

-- 
Ben Love
http://www.kylimar.com/

_______________________________________________
screen-users mailing list
screen-users-mXXj517/[email protected]
http://lists.gnu.org/mailman/listinfo/screen-users
signature.asc (application/pgp-signature, 902 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (GNU/Linux)
Comment: http://www.kylimar.com/cryptography/keys/blove.public.asc

iQIcBAEBCgAGBQJNVu7vAAoJEA6c8m/a4yhPs08P+gKvhfJn07ekbbzR0Pz241MD
sUYcBsoffnIwhwdHaZBHX25GJdaEP9Yyy8g4UtCDuadETCLftvIdbJHEUwXVGN51
P/FH6fekr5NBJih+nr9xZkBe5mH19/H5LM1L2N42f8aX9Yp+L09r8DBVwvdF0L6Q
Is7IMqi6NtRCsHdDo0Fq/pjmP60Sb82SsC6A9R5TB3ihj27wR9nRnCvpbMq0NC8x
yw/51rS14jtJuCiNMyaJyHNE12fkFJDYgmiYS+JcoSML+NJORqcXQH6uw+l2EskC
YGpujX6go6INHWn+FnX5z59jQjIXB1rniLXZ6TKX8bjFmSZtzDlPdTUEbHNGdn4u
2UyvfvG3Z+0vd9gP8oZCZPwMd07+YYQk4LyKA9v9vsSzHB2w0fnMTnxlmK2XUYsr
sCIwNMMF0t4ZckKYlFVYCKnq95VFEELplj4pH+yfM+xKWon10G9YGxKv4dd2qwxl
BzQPxGrcL86P1qJVn6Kbnj08rQnMcdJQ//q/YSYiVhjXl4QAcpdV8B5M7Mlb534M
5FHE8774tpYQb2ShbS3CJCMnyx8742cdXyi9I1Qp1OMkfBW/gHCs9x7EA7R9AxjK
78MmcarGRdiRgaQVJnaFMhsvXHQwDZ2iFINwsMb6TRqMbufdrRyGqbH1zT69eLQb
Bw2R1JWI9WTZ/W2sAKZV
=sh/s
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.