rubyの勉強中です。phpのshel_excecでrubyにデータを送り、処理した後にOk,Ng判定をphpにjsonで返す都いうことをしたのですが、実行結果のjsonではOKのはずなのにNGになってしまいます。
解決法ご教授下さい
php
1<?php 2$results = shell_exec("ruby s3downlod.rb devtouch2 51 Horseracing.mp4 /var/www/aws/"); 3echo "<pre>".$results . "</pre>"; 4 5$resJson = json_decode($results); 6 7print_r($resJson); 8 9if($resJson->result->msg == "OK"){ //<-ここがNGになる 10 echo "OK"; 11}else{ 12 echo "NG"; 13} 14
ruby
1##処理は省略。phpにjsonで渡すとこだけ書いてます 2 3if download_file('download_file', 'download_file') # => true/false 4 puts 'ダウンロード成功' 5 hash = { "result" => { "cood" => 0, "msg" =>"OK" },"data" => {"data" => $filename}} 6 json_str = JSON.pretty_generate(hash) 7 puts json_str 8else 9 puts 'ダウンロード失敗' 10 hash = { "result" => { "cood" => 7, "msg" =>NG }} 11 json_str = JSON.pretty_generate(hash) 12 puts json_str 13end 14
実行結果
ダウンロード成功
{
"result": {
"cood": 0,
"msg": "OK"
},
"data": {
{
"data": "Horseracing.mp4"
}
}
</pre>NG