du548397507 2015-04-02 16:18
浏览 507

通过php exec执行脚本,在服务器上创建一个文件

I have a php script which calls a shell script as below -

#!/bin/bash
timestamp=$(date +"%d-%m-%Y  %H:%M:%S")
echo $timestamp >> results

The php script -

<?php

$mycmd = exec('/bin/bash exectest.sh',$op,$er);
var_dump($mycmd);
var_dump($op);
echo $er."
";

?>

The php script returns error code 1 for $er but when i tried to modify the shell script to just print instead of writing to a file. the Php script then returns 0 and succeeds.

Any ideas of where I need to fix this? I have tried giving the full path for the script and also this is the same case when i tried using a python script in place of a shell script.

  • 写回答

2条回答 默认 最新

  • dongma2388 2015-04-02 16:53
    关注

    Your observation indicates that this is most likely a permission problem, e.g. the user running PHP does not have write permission to either the results file in its current working directory or the directory itself (if the file does not exist yet).

    评论

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题