0

I'm looking for a way to pipe the output of the *nix screen command to another program. In theory I would like to be able to do something like: screen -S test | php testscript.php and testscript.php receive it through php://stdin However I am open to other options if necessary.

Jason Plank
  • 2,336
  • 5
  • 31
  • 40
Nick Q.
  • 3,947
  • 2
  • 23
  • 37
  • Screen opens up a virtual terminal, it's not actually running anything, so there is nothing to pipe into the php script. If you did screen -S test then typed a command like `cat some.log | php test script.php` that would work. Why are you using screen? Can't you just push the process into the background using &? – Mike Purcell Nov 09 '11 at 20:43

1 Answers1

1
#!/usr/bin/php
<?php
$fd = fopen("php://stdin","r");
$foo = "";
while ( !feof($fd) ){
    $foo .= fread($fd,1024);
}


fclose($fd);

//rest of script

command line: screen -S test |/path/to/php/script.php makes user script file is chmod to 755

  • I tried that, however I did not receive the contents of the screen. – Nick Q. Mar 24 '11 at 17:36
  • can you pipe screen to a file? –  Mar 24 '11 at 19:58
  • Simply put not really. `screen -S test > output.txt` returns nothing, no matter the contents of the screen. However `screen -S test -L` makes a text file called screenlog.n – Nick Q. Mar 25 '11 at 01:00
  • well if you cant pipe it to a txt file you cant pipe it to anything else –  Mar 25 '11 at 03:24
  • looking at what screen does, im not surprised at the results, what is it your actully trying to achieve? –  Mar 25 '11 at 03:28