473,395 Members | 2,437 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Calling gcc from within PHP code

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 3253
b1randon
171 Expert 100+
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
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 100+
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...

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.