duanjiao3754 2012-12-03 16:38
浏览 41
已采纳

Java程序的运行方式与shell和PHP中的exec()不同

I am running a Java program on a web server and passing it arguments that come from PHP variables, and I'm running into a bit of a confusing issue. A Java program I am using seems to exhibit different behavior when I run it from shell and run it from shell_exec() in with PHP.

If I use a tool like Putty to execute the program from command line like so:

ksh runexample.ksh ClassName methodName

It runs properly, meaning the program sends a request and after about 20 seconds receives a response from gateway servers it connects to. I am then able to see that the communication was successful by seeing the resulting record in an outside database.

Now the issue arises when I execute this program from a PHP script by using.

shell_exec('path/ssh user@xxx.xx.xxxx.xx.x "cd /path/path/examples/ ksh runexample.ksh ClassName methodName;')

If I load this PHP script, and var_dump() the output, the program seems to load; but it gives me a short generic message from the Java program like "program running in connected mode etc etc", and doesn't output the usual response. The PHP script loads a page almost instantly with this output. Also, no record is created in the outside database.

I have set_time_limit(0) in the script, but could this issue be due to shell_exec() somehow timing out before the request/response in the Java program is complete?

Thanks for any insight/similar experiences, I appreciate the help!

  • 写回答

1条回答 默认 最新

  • douyimiao1993 2012-12-03 16:44
    关注

    It could be down to the fact that there is no (or another) .profile file loaded when running the application the way you do.

    I've done something quite similar to what you seem to be be doing here, and ended up posting this question here, as a follow-up to this question both of which might be of use to you now.

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

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么