du4629 2016-02-18 19:52
浏览 36
已采纳

如何在服务器中从php执行源命令

I am unable to execute a source command in linux using php.All other commands are working except this one. I need to execute the following command.

 source /root/Envs/ate/bin/activate

This activates the ate-Automatic Test Equipment.Once I activate it then I need to run a python script as the script accesses the remote server. I am able to manually run it but I am creating a tool which will automatically do it.

  <?php
  exec("source /root/Envs/ate/bin/activate", $output, $return);
  echo "Command returned $return, and output:
";
  echo exec("python box_upgrade-pradeepa.py");
  ?>

The above commands returns 1 which means there is an error.But I am not sure how to run the 'source command'. The python script will run only if the source command is successful.(the python command is correct as I replaced hello.py and it ran fine.) Could you pls help me as I am really stuck for a week? Thanks a lot..

  • 写回答

1条回答 默认 最新

  • doubo1871 2016-02-22 23:51
    关注

    I found out the error. Since I am doing it using php (for a web tool) the user is Apache. 'Apache' user is unable to access the script in root folder. Moving it to another directory, I am able to run the script fine.

    Thanks all..

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

报告相同问题?

悬赏问题

  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用
  • ¥20 51单片机学习中的问题
  • ¥30 Windows Server 2016利用兩張網卡處理兩個不同網絡
  • ¥15 Python中knn问题
  • ¥15 使用C#,asp.net读取Excel文件并保存到Oracle数据库