如何使用php在Windows命令提示符下编译c代码

时间:2014-04-18 06:42:20

标签: php c windows

在PHP中使用passthru函数我可以运行exe例如hello.exe并获得其结果但无法使用命令tcc hello.c通过php脚本在Windows命令提示符下编译例如hello.c。

所以问题是如何使用php脚本在Windows命令提示符下运行commad tcc hello.c。 php脚本& cmd.exe在来机器上。

OS Windows XP。

我要编译的代码是hello.c,如下所示。

执行hello.exe的php脚本也在下面给出。

来自hello.c的

代码

#include<stdio.h>

void main(void)
      {

    printf("hello");

      }

成功访问并显示hello.exe的php代码

enter code here
<?php
echo "Remote compilation:";
$path = escapeshellcmd('C:\\TC\\BIN\\HELLO.exe');
passthru( $path, $return_var);
?>

请指导 问候

1 个答案:

答案 0 :(得分:0)

从PHP文档:

  

passthru()函数类似于exec()函数   执行命令。应该使用此函数代替exec()或   system()当Unix命令的输出是二进制数据时   需要直接传递回浏览器。

但是在这里你不希望从tcc生成二进制数据并传递给浏览器。更合适的函数是shell_exec()。 E.g:

<?php
echo "Remote compilation:";
$command = escapeshellcmd('YOUR TCC COMPILE COMMAND HERE');
shell_exec($command);
?>