我一直在尝试从Php执行此行echo exec('hi.exe $file',$results,$status);
。分配给$ file的值是文件名 hi.txt (即$ file = hi.txt)。
但每次我尝试使用相同的行运行我的代码时,它显示的错误为$file file not found
,就好像我在命令提示符中运行相同的hi.exe hi.txt
一样。
并且如果我尝试使用文件名而不是来自php的变量运行相同的行,即exec('hi.exe hi.txt',$results,$status)
,浏览器会长时间执行而不提供输出。
请有人告诉我哪里出错了!
答案 0 :(得分:2)
您使用的是单引号,而不是双引号。将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
答案 1 :(得分:1)
单引号不会扩展变量。你可能意味着:
echo exec("hi.exe $file",$results,$status);