Jump to content

problem with program execution (g++)


kavent

Recommended Posts

Hi everyone, I am new to PHP and trying to do something as the following:
Allow users to enter their c++ code in text area, which will be saved in main.cpp.
Then I tried to run g++ (from /usr/bin/g++) to compile this main.cpp, but nothing happened. It seems that I can't run other programs in /usr/bin/ either.

<?php
$cmd = "less main.cpp; g++ main.cpp -o test.out;";
echo shell_exec($cmd);
?>

shows main.cpp with no problem, but it doesn't compile. g++ has permission of 755, safe_mode is off, and I don't have root on the server.

Any help would be appreciated. Thanks!
Link to comment
https://forums.phpfreaks.com/topic/31836-problem-with-program-execution-g/
Share on other sites

It does work, thanks!
However, I don't quite understand the syntax "&> /tmp/g++.out;". Actually, what I tried to do is to use a application called dot, which is similar to g++, to compile DOT file. The commend looks like this:

$cmd = "dot test.dot -Tsvg -o test.svg;";

Would you help me with this one as well? Thank you!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.