简体   繁体   English

调用shell_exec显示来自php的奇怪行为

[英]Calling shell_exec shows weird behavior from php

Following php code works and I get output: 下面的PHP代码工作,我得到输出:

<?php

echo 'hello world';
echo shell_exec('ls -la');

?>

// Output
hello worldtotal 2064 drwxrwxrwx. 3 root root 4096 Jul 4 10:26 . drwxr-xr-x. 4 root root 4096 Jul 4 10:17 .. -rw-rw-r--. 1 arun arun 2089447 Jul 3 11:09 cakephp-cakephp-2.3.6-0-gd10df32.zip -rw-r--r--. 1 root root 32 Jun 18 18:01 info.php drwxrwxrwx. 7 arun arun 4096 Jul 3 12:23 nykkos -rw-r--r--. 1 arun arun 76 Jul 4 10:26 test.php

The following code does not work: 以下代码不起作用:

<?php

echo 'hello world';
echo shell_exec("java -jar /var/www/html/nyk/app/webroot/Converter.jar $id");

?>

It just shows a blank white screen. 它只显示空白屏幕。 Even the simple java -version when used in the above php code gives a blank screen. 即使在上述php代码中使用简单的java -version,也会出现空白屏幕。 Even the 'hello world' does not get printed. 甚至“ hello world”也不会被打印出来。

Whereas the java commands discussed above work without any issues from terminal. 鉴于以上讨论的Java命令可以正常运行,而终端没有任何问题。 My OS is fedora. 我的操作系统是fedora。

What is the reason behind this strange behaviour and how can I overcome the same? 这种奇怪行为的背后是什么原因,我该如何克服?

Any help is much appreciated. 任何帮助深表感谢。

I had this problem using MAMP on OSX. 我在OSX上使用MAMP时遇到此问题。 I think that it should be the same issue. 我认为应该是同一问题。 Try open the file envvars that in MAC is on MAMP/Library/bin/envvars. 尝试打开MAC中MAMP / Library / bin / envvars上的文件envvars。 Try to comment the four lines of if and else. 尝试注释if和else的四行。 this will looks like: 这看起来像:

#if test "x$DYLD_LIBRARY_PATH" != "x" ; then
#  DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib:$DYLD_LIBRARY_PATH"
#else
#  DYLD_LIBRARY_PATH="/Applications/MAMP/Library/lib"

Don't forget to reset Apache. 不要忘记重置Apache。 It works fine for me! 这对我来说可以! I hope that you can enjoy it. 希望您能喜欢。 Good Lucky! 好幸运!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM