dsy19890123 2016-06-23 10:55
浏览 65

在localhost上从Java调用时,Php exec无法正常运行

I have a problem running the exec command from within a php script.
here's the detailed scenario:

  • I have an executable my_exe which runs from command line. This executable uses an environment variable, so I prepend the command with MY_VARIABLE='value' (works fine).

  • I use the exec command to run this executable from a Php script. ex: exec("MY_VARIABLE='value' my_exe"); (works fine too, tested in a browser)

  • The problem is in this part. When I call the php script from a Java program using HttpUrlConnection, I have two cases: if I run the Java program from outside the server (using public IP address) I get the good results, but when I run it from the server (using local IP, form command line ex. "java -jar /path/to/my/jar"), the Php works but the exec doesn't seem to be working properly. The environment variable is not being set in this case, so the executable runs but without the right values, so I get no results.

Any help is appreciated. I'm really stuck here. My guess is that there is a problem with Php or Java permissions, but I can't figure it out.

  • 写回答

1条回答 默认 最新

  • doupai6875 2016-06-23 21:46
    关注

    Strange command exec("MY_VARIABLE='value' my_exe");... it will work only on linux machine and will not on windows. As a first step, try to rewrite you php code like this:

    putenv("MY_VARIABLE=value");
    exec("my_exe");
    

    and see what happen.

    评论

报告相同问题?

悬赏问题

  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏