douping1825 2011-10-16 02:33
浏览 72
已采纳

php exec bash脚本:没有这样的文件或目录

I have a few bash and perl scripts which has been asked to be made executable through a web based interface. Nothing fancy, just for easy access. PHP seemed to be the quick and dirty solution for the purpose [through exec()]. So I turned off the safe mode in php.ini and tried

$output = array();
exec('/var/www/vhosts/default/htdocs/scripts/RUN.sh',$OUTPUT);
print_r($output);
var_dump($output);

Now whatever files are accessed in the RUN.sh script (accessed though a relative path) are not found. Is there any way of getting this to work without giving complete path to every single redirect (or any file for that matter) that is being accessed in the scripts?


After applying the accepted solution:

Say one line form the script:

time python idsplitter.py OUTPUT/TMP/tokens OUTPUT/token_splits
echo "done"

While the time-s output gets pushed to error_log file, "done" is never passed to the $OUTPUT array. The returned value in the third argument to exec(), when printed on page gives 0.


Update: time command puts it out to stderr so if do `

t=`time some_command 2>&1`

then also nothing gets stored in t. So that makes sense. Thanks for the help everyone ...

  • 写回答

2条回答 默认 最新

  • douxin8749 2011-10-16 02:38
    关注

    Change the current working directory as part of the script itself.

    Your working directory, from the perspective of the RUN.sh script, isn't what you think it is. Therefore, relative paths in the script don't point where intended.

    To fix it you need to force the current working directory to be the one that works with the relative paths. So, either:

    • use absolute paths, or
    • change the current working directory via calling cd [/absolute/path] in the RUN.sh script, to force it to be correct.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器