resourse は返るけれども null っぽいとか、よくわからん事になってた。
こんなカンジ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$handle = popen('command', 'r'); | |
$buffer = fgets($handle, 8192); | |
var_dump($buffer); // "" -> false |
なんで空なのかさっぱりわからず、実際にはコマンドの引数がいろいろついてるんだけど、
それが正しくないせいでうまく言ってないもんだと思ってた。
今までもプログラムで動いていたし。
いろいろ修正してもわからず。
基本に戻って PHP マニュアルを確認。
http://php.net/manual/ja/function.popen.php
/* リダイレクトにより、標準エラー出力を取得します */
$handle = popen('/path/to/executable 2>&1', 'r');
echo "'$handle'; " . gettype($handle) . "\n";
$read = fread($handle, 2096);
echo $read;pclose($handle);
お?と思い修正。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$handle = popen('somecommand 2>&1', 'r'); | |
$buffer = fgets($handle, 8192); |
そしたらこんなエラーが出てました
/lib/ld-linux.so.2: bad ELF interpreter: No such file or directoryあ、 /lib/ld-linux.so.2 が無いんだと思って。おもむろに
yum install ld-linux.so.2これで、32bit のコマンドも動きました。
Installing:
glibc i686
Installing for dependencies:
nss-softokn-freebl i686