no_gravity no_gravity - 1 month ago 10
Bash Question

passthru hangs if the executed command writes to the clipboard

Put this in a file "a.php" and execute it. It works just fine:

#!/usr/bin/php
<?php
$p = popen('xclip -i -selection clipboard', 'w');
fwrite($p, 'Hello Word');
pclose($p);


Now make a file "b.php" and execute it:

#!/usr/bin/php
<?php
passthru('./a.php');


It hangs forever. Why?

(If you do not have xclip, you can install it with apt-get install xclip)

Answer

"xclip -i -selection clipboard > /dev/null" should fix it

xclip doesn't close the STDOUT.

related to: this questions answer