douti6740 2012-03-25 23:37
浏览 97

无法通过php系统执行g ++()

I am trying to compile a a c++ file on the server. I have a Windows 7 64 bit install along with mingw32 c/c++ compiler installed on the system running WampServer2.0 (php 5.3.0). I have already set the env variables to relative paths (c:\MinGW\bin). The following piece of code does not produce any executable in the Dest_folder, however the command runs perfectly well when executed from cmd (command prompt) and generates the executable

<?php
$string = system("g++ -o C:\\wamp\\www\\Dest_folder\\file.exe C:\\wamp\\www\\Dest_folder\\file.cpp", $retval);
echo $retval;
echo $string;
?> 

The $string variable should returns the last line of the command output on success, and FALSE on failure (which in this case does not return anything) and the $retval variable returns 1. Am I doing anything wrong? Also I noticed, every successful system() call (all other calls except for g++ compilation) produces 0 as $retval.

  • 写回答

2条回答 默认 最新

  • duanfu5239 2012-03-25 23:47
    关注

    The backslash has special meaning in PHP string literals, so you need to escape it:

    $string = system("g++ -o C:\\wamp\\www\\Dest_folder\\file.exe C:\\wamp\www\\Dest_folder\\file.cpp", $retval);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题