Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux Screen utility does not echo to screen after redirection

Tags:

bash

shell

php

I am testing the redirection of running a PHP program into a screen.

Script does this:

<?php

for( $i=1; $i<=1000; $i++ )
{
        sleep(1);
        echo $i;
        echo "\n";
}

I am running the above with:

screen -d -m bash -c 'php forlog.php >> ~/forlog.log 2>&1'

Redirection works fine but when I attach to the screen I have no output(blank screen) .

Is there anyway to have the output redirected to both file and within the screen?

P.S: I don't want to use nohup. Also when not redirected, the output can be seen within the screen just fine.

like image 499
isaac.hazan Avatar asked May 21 '26 13:05

isaac.hazan


1 Answers

You could use tee to append to the log file and write to STDOUT (of screen) at the same time.

screen -d -m bash -c 'php forlog.php 2>&1 | tee -a ~/forlog.log'
like image 54
Rayne Avatar answered May 24 '26 03:05

Rayne