douzi8127 2013-03-12 16:14
浏览 194
已采纳

PHP shell_exec()不会返回正确的状态

I'm trying to run a sh script file from the php function shell_exec() but every time the return is uncorrect.

This is the sh file content:

if [[ -z $1 ]]
then
        echo "svn st: NULL"
else
        command=$(ssh -q USER@IP_OF_THE_REMOTE_NODE "svn st $1")
        if [[ -z $command ]]
        then
                test="svn st: OK"
        else
                test="svn st: KO"
        fi
        echo $test
fi

every time that I run this sh script from the shell the echo is ALWAYS correct. The "$1" contains the working directory that I have to check.

But if I run the same script in this way:

$w_path = $working_path['path'];
$com = "sh /tmp/my_script_test.sh $w_path";

echo "content com ".$com;

$res = shell_exec($com);

echo "content res ".$res;

the last echo print ALWAYS "svn st: OK", that is correct for some $w_path, but completely uncorrect for others! Why? How can I find the mistake?

I don't think that is a ssh key problem cause I used a guide to resolve that and now I don't need to insert the password for the remote server.

Thanks Regards

  • 写回答

1条回答 默认 最新

  • dongqianzhan8325 2013-08-28 08:09
    关注

    Change

            command=$(ssh -q USER@IP_OF_THE_REMOTE_NODE "svn st $1")
            if [[ -z $command ]]
    

    to

            if ssh -q USER@IP_OF_THE_REMOTE_NODE "svn st $1"
    

    and remember: Whenever something doesn't work, it's because it's too complicated (can't recall where I read that).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型