PHP exec 无法与 gcc 一起使用

发布于 2024-08-30 04:53:49 字数 584 浏览 1 评论 0原文

我只是花了几个小时才解决这个问题。我试图让 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

峩卟喜欢 2024-09-06 04:53:49

您正在编译该程序,但从未执行它。

  1. 检查一下是否编译成功
    程序通过运行 foo.out 来工作。
  2. 假设 foo.out 已编译
    正确,然后运行 ​​foo.out。

You are compiling the program, but you are never executing it.

  1. Check to see that the compiled
    program works by running foo.out.
  2. Assuming foo.out compiled
    correctly, then run foo.out.
海的爱人是光 2024-09-06 04:53:49

我发现了问题。我随机生成文件名并创建文件。我试图在文件处理程序上运行 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文