Possible Duplicate:
Why is PHP not replacing the variable in string?
我一直在尝试执行这一行echo exec('hi.exe $file',$results,$status);
来自 Ph.D.其中分配给 $file 的值是文件名 hi.txt(即 $file = hi.txt)。
但是每次我尝试使用同一行运行代码时,它都会显示错误为 $file file not found
就好像我运行相同的 hi.exe hi.txt
在命令提示符下它的工作。
而且,如果我尝试使用文件名而不是 php 中的变量运行同一行,即 exec('hi.exe hi.txt',$results,$status)
,浏览器长时间执行而不给出输出。
请有人告诉我哪里出错了!
最佳答案
您使用的是单引号,而不是双引号。将 echo exec('hi.exe $file',$results,$status);
更改为:
echo exec("hi.exe $file",$results,$status);
或者使用点,如下所示:
echo exec('hi.exe '.$file,$results,$status);
在 PHP 中,使用单引号不会将 $file
转换为 hi.txt
;它只是保留为文字字符串“$file”。使用双引号或点连接将 $file
实际扩展为 hi.txt
关于php - 从 Php 脚本执行 .exe 文件时遇到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13410822/