To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > Misc Help > Linux/Unix Help

Linux/Unix Help Help with server-side Linux and Unix issues

Reply
 
Thread Tools Rate Thread Display Modes
Old 09-06-2002, 04:32 PM   #1
TerryG
Junior Member
 
Join Date: Sep 2002
Location: Texas
Posts: 3
system calls from php

Not sure if this is a unix problem or php, but I'm
posting here:


I'm trying to create a web based c++ compiler
for my computer science students. This will
allow them to submit small c++ programs and
view the errors or the output.

They type their code into a text box and when
submitted, I write there code to a file and
then attempt to compile it with a call to g++
using the system() function or ` backtick operator.

Simple unix commands work, like the following:
$command = `more hello.txt`;
echo"$command";
or
$command = `ls -l`;
echo"<pre>$command</pre>";
or
system("ls -l");

But the following will not work:

system("g++ hello.c >& err.out");
or
$command=`g++ hello.c >& err.out`;
echo"<pre>$command</pre>";

the ">&" forces the output to a file called err.out
wich gets created when ran from the command
line, but not when called from php.

I don't think it's a simple file permissions problem, played
that angle for a while.

Can this be fixed with php or is this more an administration
problem? or what?


thanks in advance
TerryG is offline   Reply With Quote
Old 09-07-2002, 01:41 AM   #2
nashirak
Senior Member
 
Join Date: Jul 2001
Posts: 305
I think it actually still might be a permissions issue. I tested your program using this script:

PHP Code:
<?php

   $command
= "gcc ". $com ." >& err.out";
   echo
$command;

   
system($command);

?>
then inserted a nice ?com=hello.c to try and test it. Well you are right. It will write out and create a file named err.out after gcc is done. Why? Because while it does have permission to run gcc, you do not have permission as user www-data (or nobody) to create a file inside of the directory. How did I get around this? 2 ways. First try and creating a file named err.out and changing its permissions to 755. Or if that doesnt suit you too well try creating a direcotry and changing the permissions on this directory to 755. Then stick the error file in there like:

mkdir nobody
chmod 755 nobody

PHP Code:
<?php

   $command
= "gcc ". $com ." >& nobody/err.out";
   echo
$command;

   
system($command);

?>

I hope that helps.
nashirak is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 04:59 AM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.