简体   繁体   English

c ++程序无法通过php脚本(例如exec(),shell_exec(),system()等命令)执行

[英]c++ program not getting executed using php script with commands like exec(),shell_exec(),system()

I am trying to compile and execute c++ program using php script in Ubuntu 12.04.The c++ program is getting compiled and even a.out is getting created but the only problem is that ./a.out is not working. 我正在尝试在Ubuntu 12.04中使用php脚本编译和执行c ++程序。正在编译c ++程序,甚至创建了a.out,但是唯一的问题是./a.out无法正常工作。 I have tried most of commands to run ./a.out like system(),exec(),shell_exec(),backtick,passthru etc. Now for the sake of simplicity a.out is created in the same directory in which the php file resides.I am posting here the code 我已经尝试了大多数命令来运行./a.out,例如system(),exec(),shell_exec(),backtick,passthru等。为了简单起见,现在在与php相同的目录中创建a.out文件驻留。我在此处发布代码

 $target = $_GET['name'];
 chmod($target,0777); 
 $handle = fopen("compile.sh", "x+");
 chmod("compile.sh",0777);
 $data = "g++ ".$target;     
 fwrite($handle, $data);
 fclose($handle);  
 system("sh compile.sh");    
 chmod("a.out", 0777);   
 system("./a.out");

I am getting the name of file to be compiled from the url and so on.The above code works fine upto penultimate line ie chmod("a.out",0777) but the output of cpp program is not getting displayed. 我正在从url等处获取要编译的文件的名称。上面的代码在倒数第二行,即chmod(“ a.out”,0777)上正常工作,但未显示cpp程序的输出。 * And the most funniest part is that same code works perfectly fine for c program *after changing g++ to gcc. * 最有趣的部分是,在将g ++更改为gcc之后,相同的代码对于c程序来说可以正常工作

i solved the problem which was due to file libgcc_s.so.1 giving an error 我解决了由于文件libgcc_s.so.1给出错误的问题

/lib/libgcc_s.so.1 : version 'GCC_4.2.0' not found (required by /usr/lib/libstdcc+.so.6) /lib/libgcc_s.so.1:找不到版本'GCC_4.2.0'(/usr/lib/libstdcc+.so.6要求)

all i did was to replace this file which lies in the lib folder of lampp directory by the libgcc_s.so in gcc directory and renaming it to libgcc_s.so.1. 我所做的只是用gcc目录中的libgcc_s.so替换了lampp目录的lib文件夹中的文件,并将其重命名为libgcc_s.so.1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM