linux下exec函数不返回结果

执行的返回值是127
返回结果为空,
代码:
exec("su - root",$aa,$bb);
echo $aa[0]."<br/>";
echo $bb."<br/>";
exec("123456");
别的代码也是一样,比如ls -la 之类的,
运行环境是centos,php的safe_mode是关着的。
补充:exech和system都能执行例如 dir 命令,但是ls -l 却不行,这是个新的问题,我不知道这代表了什么。

yes you are right , exec 是不返回的,它将当前进程的内容替换成要执行的程序的内容,这样就可以运行一个新的程序了。如果exec 返回了说明执行新程序出错了,内存不够啊,系统异常啊。。追问

不是吧,在wamp集成环境下执行exec能得到他的返回结果,
这个是有人验证过的。

追答

我说的是系统调用,你这说提shell 里的,还是其它语言里面的

温馨提示:答案为网友推荐,仅供参考
第1个回答  2012-04-23
不知道你这里的exec是不是php里面的还是系统bash内置的。
如果是php的
这是语法
string exec ( string $command [, array &$output [, int &$return_var ]] )
command

The command that will be executed.
output

If the output argument is present, then the specified array will be filled with every line of output from the command. Trailing whitespace, such as \n, is not included in this array. Note that if the array already contains some elements, exec() will append to the end of the array. If you do not want the function to append elements, call unset() on the array before passing it to exec().
return_var

If the return_var argument is present along with the output argument, then the return status of the executed command will be written to this variable.

Return Values

The last line from the result of the command. If you need to execute a command and have all the data from the command passed directly back without any interference, use the passthru() function.

To get the output of the executed command, be sure to set and use the output parameter.
意思就是说输出和返回 都是可选参数,你要指定了才有!!
具体的你查看一下php手册,一贴网址就不显示了追问

手册我查了,后面两个参数不论是指定还是直接把写成$a=exec(....);的行使,都没有内容输出,而且最后的参数表示命令的执行情况,我这的返回值是127,表示什么意思,我不是很清楚。

追答

我个人觉得都看不懂你的代码?你写成这样试试,我认为你的command有问题才会得到127

本回答被提问者采纳
相似回答