PHP exec 无法与 gcc 一起使用
我只是花了几个小时才解决这个问题。我试图让 gcc 从 PHP 中编译一个文件。
$command = "/usr/bin/gcc /var/www/progpad/temp/tNu7rq.c -o /var/www/progpad/temp/tNu7rq.out";
exec($command, $output, $returnVal);
echo $returnVal."<br />"; //returns 1 and no output file created.
我在我自己的 ubuntu 服务器上运行它,并且都
/var/www/progpad/
/var/www/progpad/temp/
设置了 chmod 777。如果我复制并粘贴命令字符串,然后将其粘贴到终端中,它就可以正常工作。
另外,如果我将命令字符串替换为“Then”之类的内容
$command = "echo test > test.txt";
,那么创建文本文件就没有问题了。我在这里可能做错了什么???
I just spent a few hours pulling my hair out over this. I'm trying to get gcc to compile a file from within PHP.
$command = "/usr/bin/gcc /var/www/progpad/temp/tNu7rq.c -o /var/www/progpad/temp/tNu7rq.out";
exec($command, $output, $returnVal);
echo $returnVal."<br />"; //returns 1 and no output file created.
I'm running this on my own ubuntu server and both
/var/www/progpad/
/var/www/progpad/temp/
have chmod 777 set. If I copy and paste the command string, and paste it into the terminal it works perfectly.
Also if I replace the command string with something like
$command = "echo test > test.txt";
Then this has no problem creating the text file. What could I possibly be doing wrong here???
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您正在编译该程序,但从未执行它。
程序通过运行 foo.out 来工作。
正确,然后运行 foo.out。
You are compiling the program, but you are never executing it.
program works by running foo.out.
correctly, then run foo.out.
我发现了问题。我随机生成文件名并创建文件。我试图在文件处理程序上运行 fclose() 之前编译该文件。
I found the problem. I was randomly generating file names, and creating the file. I was trying to compile the file before running fclose() on the file handler.