473,471 Members | 2,040 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Calling gcc from within PHP code

4 New Member
I am currently trying to create a php script that will call gcc and pass various arguments so that you can compile a c program on a remote server after uploading your raw code. I'm using something along the following lines but as of yet it's not working:

[PHP]
$command = "gcc /home/username/sourcefile.c";
$output = shell_exec($command);
echo $output;
[/PHP]

When I run this I get a blank browser window, and the executable file that should be produced is not. I have tried creating a batch file containing the $command string and then replacing $command in my script with
[PHP]
$command = "sh batchfile";
[/PHP]
but I get the same result.

Any ideas? I know the shell_exec command works (i.e. PHP safe mode is not on) as I can run an "ls" command just fine, it appears only the call to gcc does not work, even if I put in the full path (/usr/bin/gcc). The script is running on a web hosting site Linux server and I've verified that gcc exists. I have also tried running this on a different Linux server at work with the same results.

Many thanks for any help!
Jon
Dec 13 '06 #1
3 3256
b1randon
171 Recognized Expert New Member
I am currently trying to create a php script that will call gcc and pass various arguments so that you can compile a c program on a remote server after uploading your raw code. I'm using something along the following lines but as of yet it's not working:

[PHP]
$command = "gcc /home/username/sourcefile.c";
$output = shell_exec($command);
echo $output;
[/PHP]

When I run this I get a blank browser window, and the executable file that should be produced is not. I have tried creating a batch file containing the $command string and then replacing $command in my script with
[PHP]
$command = "sh batchfile";
[/PHP]
but I get the same result.

Any ideas? I know the shell_exec command works (i.e. PHP safe mode is not on) as I can run an "ls" command just fine, it appears only the call to gcc does not work, even if I put in the full path (/usr/bin/gcc). The script is running on a web hosting site Linux server and I've verified that gcc exists. I have also tried running this on a different Linux server at work with the same results.

Many thanks for any help!
Jon
This might be a long shot but have you checked for a permissions problem? I think php usually runs things in a really underprivileged account. See if you can change the permissions or verify that they are adequate. Good luck! This is a neat task.
Dec 14 '06 #2
joxtoby
4 New Member
This might be a long shot but have you checked for a permissions problem? I think php usually runs things in a really underprivileged account. See if you can change the permissions or verify that they are adequate. Good luck! This is a neat task.
That was the problem! Can't believe I overlooked it, many thanks!
Dec 14 '06 #3
macklin01
145 New Member
I've noticed similar permissions issues when you want PHP to write a log, for instance.

I have a question, though: what's the best way to elevate the permissions so that PHP can do what it needs without overly compromising security? (Assuming a *nix environment.) Certainly, doing a chmod a+w isn't the greatest way to go. ;)

Thanks for posting on a fun topic. :) -- Paul
Dec 14 '06 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Andrew Boothman | last post by:
Hi, This may be the dumbest question ever, but in the following code (using PHP 4.3.8) how do I call b() from within a()? class test { function a() { print "a called"; b();
3
by: Glenn C. Rhoads | last post by:
I'm having a problem calling a C function from a publicly available library file. To get the code to compile, I had to declare the function as an external C function as follows. extern "C"...
4
by: Zeebra3 | last post by:
Here goes: I have a web form with several asp:dropdownlists, with which, when selection is changed I want to fire an event defined in some clientside js. The content of the clientside code is...
8
by: Brett Robichaud | last post by:
I understand how code-behind can handle events for a page, but can I call a code-behind method from within a <script> tag in my ASP.Net page, or can I only call methods defined in other <script>...
4
by: Martin Feuersteiner | last post by:
Dear Group I'm using VB to write an aspnet application. I would like to call a javascript function from within a VB Sub or VB Function, is it possible? My code is something like this: VB...
2
by: Joerg Battermann | last post by:
Hello there, I have a quick question: When calling a function B from within a function A, is it possible get information about the calling function A (e.g. name, values passed over etc) from...
3
by: Klaus | last post by:
Hi, I have an existing VC 6 MFC application which communicates asynchronly with a VC 2005 managed code dll. I use an unmanaged base class with virtual functions to access methods in the MFC...
15
by: =?Utf-8?B?VG9tIENvcmNvcmFu?= | last post by:
I've been led to believe by several articles, particularly Eric Gunnerson's C# Calling Code Dynamically, that calling a method dynamically through Reflection was much slower than through a...
9
by: Pubs | last post by:
Hi all, I want to call a function with some intial parameters with in a thread. At the end of the function execution it should return a value to the caller. Caller is outside the thread. ...
3
by: keirnus | last post by:
Hello once again... I made a function in Excel. The function does some error checking within the Excel file. To be easy for me, I want my code in MS Access to simply call the function in Excel....
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.