471,354 Members | 2,215 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Using PHP to compile uploaded sourcecode with cygwins gcc?

Hello, I have an intresting problem: I want to let users upload sourcecode
and then compile it using my cygwin gcc... But one thing at a time... I
can't get that gcc to execute...

shell_exec("gcc temp.c"); # Doesn't work as that will use MinGW
shell_exec("D:\\cygwin\\bin\\gcc.exe temp.c"); /* Gives some error about dll
stuff (procedure not found I think)*/

So my next though was to open "bash.exe --login -I" and fwrite the
commands... But that still tries to use the mingw compiler it seems...Guess
there's some environiment problem... So I figured I could use virtual() to a
cgi script with this as first line:
#!D:/cygwin/bin/perl
and then use the perl open(), with |/cygdrive/d/bin/gcc.exe temp.c as
argument... Seems like it executes the right compiler then, but then I get
millions of errors caused by *.h can't be opened (yes, the source tries to
include them), so I though about passing -B /usr/include to it... But those
errors still appear... Also, it feels somewhat bad to use virtual() to call
perl scripts, so I was wondering if you ppl have some nice idea on how I
would do it?

Paths:
Cygwin: d:\cygwin
PHP: C:\PHP (4.3.3, zip from php.net, installed as Apache 1.3.28 module)
Apache: D:\Apache (installed using .msi package, as service)
Perl: D:\perl\bin\perl.exe (or D:\cygwin\bin\perl.exe)
Script: D:\www2\compile.php, D:\www2\compiling\compile_cyg.cgi
Sourcecode: D:\www2\compiling\temp.c (yes, only one file yet, that's a later
problem)

pwd returns I'm in the 'compiling' folder, in the php script, I chdir() to
get into that folder...

Can anyone help, please? Security is not a concern, it's private, and it's
for learning purposes mostly... I use winXP home... I can install stuff like
I want, that's not a problem... Thanks in advance!
--
// DvDmanDT
MSN: dv******@hotmail.com
Mail: dv******@telia.com
Jul 17 '05 #1
4 4196
On Sat, 20 Sep 2003 15:45:14 +0000, DvDmanDT wrote:
Hello, I have an intresting problem: I want to let users upload sourcecode
and then compile it using my cygwin gcc... But one thing at a time... I
can't get that gcc to execute...

shell_exec("gcc temp.c"); # Doesn't work as that will use MinGW
shell_exec("D:\\cygwin\\bin\\gcc.exe temp.c"); /* Gives some error about dll
stuff (procedure not found I think)*/
my guess is:
find out what environment variables need to be set in order for window's
shell to find the correct DLLs, and set them before calling shell_exec

it's just a guess though, I'm not sure that's the problem.


So my next though was to open "bash.exe --login -I" and fwrite the
commands... But that still tries to use the mingw compiler it seems...Guess
there's some environiment problem...


well what's the default compiler when you run a bash shell under cygwin ?

--
luc wastiaux
email: luc-at-4002-dot-org
jabber: lu*@jabber.4002.org

Jul 17 '05 #2
In cygwin, /bin/gcc or /usr/bin/gcc is used (same file, it's linked it
seems)... This works as Cygwin sets it's own PATH variable... But for some
reason, it seems like that doesn't happend from Apache/PHP/Perl.. The only
env var that should have to be set is Path, and that should include
D:\cygwin\bin which it does... Here's my PATH (only first items as it's
pretty long):

c:\develop\mingw32\bin;D:\djgpp\bin;D:\cygwin\bin; D:\cygwin\usr\sbin

PATH is the same for system and my account... Also, what would my `` command
be? I have serious problems... Also, what dir should I try to include (I
mean, /usr/include or D:\cygwin\usr\include)?

Thanks for your help
--
// DvDmanDT
MSN: dv******@hotmail.com
Mail: dv******@telia.com
"luc wastiaux" <lu*@nospam.invalid> skrev i meddelandet
news:pa****************************@nospam.invalid ...
On Sat, 20 Sep 2003 15:45:14 +0000, DvDmanDT wrote:
Hello, I have an intresting problem: I want to let users upload sourcecode and then compile it using my cygwin gcc... But one thing at a time... I
can't get that gcc to execute...

shell_exec("gcc temp.c"); # Doesn't work as that will use MinGW
shell_exec("D:\\cygwin\\bin\\gcc.exe temp.c"); /* Gives some error about dll stuff (procedure not found I think)*/


my guess is:
find out what environment variables need to be set in order for window's
shell to find the correct DLLs, and set them before calling shell_exec

it's just a guess though, I'm not sure that's the problem.


So my next though was to open "bash.exe --login -I" and fwrite the
commands... But that still tries to use the mingw compiler it seems...Guess there's some environiment problem...


well what's the default compiler when you run a bash shell under cygwin ?

--
luc wastiaux
email: luc-at-4002-dot-org
jabber: lu*@jabber.4002.org

Jul 17 '05 #3

"DvDmanDT" <dv******@telia.com> schreef in bericht
news:LI*******************@newsc.telia.net...
In cygwin, /bin/gcc or /usr/bin/gcc is used (same file, it's linked it
seems)... This works as Cygwin sets it's own PATH variable... But for some
reason, it seems like that doesn't happend from Apache/PHP/Perl.. The only
env var that should have to be set is Path, and that should include
D:\cygwin\bin which it does... Here's my PATH (only first items as it's
pretty long):


Try it with a batch file that sets the required path and call this with
shell_exec. This batch file could look something like the following:

SET path = %path%;D:\cygwin\bin;D:\cygwin\usr\sbin
D:\cygwin\bin\gcc.exe %1

Call it as: 'name_of_batch_file.bat source.c'
HTH,
JW

Jul 17 '05 #4
Why set it last in the path? First would be better... *testing* damn,
refuses to include the header files... -B seems to be simply ignored... :S

--
// DvDmanDT
MSN: dv******@hotmail.com
Mail: dv******@telia.com
"Janwillem Borleffs" <jw*@jwbfoto.demon.nl> skrev i meddelandet
news:3f***********************@news.euronet.nl...

"DvDmanDT" <dv******@telia.com> schreef in bericht
news:LI*******************@newsc.telia.net...
In cygwin, /bin/gcc or /usr/bin/gcc is used (same file, it's linked it
seems)... This works as Cygwin sets it's own PATH variable... But for some reason, it seems like that doesn't happend from Apache/PHP/Perl.. The only env var that should have to be set is Path, and that should include
D:\cygwin\bin which it does... Here's my PATH (only first items as it's
pretty long):


Try it with a batch file that sets the required path and call this with
shell_exec. This batch file could look something like the following:

SET path = %path%;D:\cygwin\bin;D:\cygwin\usr\sbin
D:\cygwin\bin\gcc.exe %1

Call it as: 'name_of_batch_file.bat source.c'
HTH,
JW

Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by IkBenHet | last post: by
reply views Thread by XIAOLAOHU | last post: by

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.