Connecting Tech Pros Worldwide Help | Site Map

Using PHP to compile uploaded sourcecode with cygwins gcc?

DvDmanDT
Guest
 
Posts: n/a
#1: Jul 17 '05
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: dvdmandt@hotmail.com
Mail: dvdmandt@telia.com


luc wastiaux
Guest
 
Posts: n/a
#2: Jul 17 '05

re: Using PHP to compile uploaded sourcecode with cygwins gcc?


On Sat, 20 Sep 2003 15:45:14 +0000, DvDmanDT wrote:
[color=blue]
> 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)*/[/color]

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.

[color=blue]
>
> 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...[/color]

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

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

DvDmanDT
Guest
 
Posts: n/a
#3: Jul 17 '05

re: Using PHP to compile uploaded sourcecode with cygwins gcc?


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: dvdmandt@hotmail.com
Mail: dvdmandt@telia.com
"luc wastiaux" <luc@nospam.invalid> skrev i meddelandet
news:pan.2003.09.20.18.57.49.204369@nospam.invalid ...[color=blue]
> On Sat, 20 Sep 2003 15:45:14 +0000, DvDmanDT wrote:
>[color=green]
> > Hello, I have an intresting problem: I want to let users upload[/color][/color]
sourcecode[color=blue][color=green]
> > 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[/color][/color]
dll[color=blue][color=green]
> > stuff (procedure not found I think)*/[/color]
>
> 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.
>
>[color=green]
> >
> > 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[/color][/color]
seems...Guess[color=blue][color=green]
> > there's some environiment problem...[/color]
>
> well what's the default compiler when you run a bash shell under cygwin ?
>
> --
> luc wastiaux
> email: luc-at-4002-dot-org
> jabber: luc@jabber.4002.org
>[/color]


Janwillem Borleffs
Guest
 
Posts: n/a
#4: Jul 17 '05

re: Using PHP to compile uploaded sourcecode with cygwins gcc?



"DvDmanDT" <dvdmandt@telia.com> schreef in bericht
news:LI1bb.29418$dP1.84791@newsc.telia.net...[color=blue]
> 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):
>[/color]

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



DvDmanDT
Guest
 
Posts: n/a
#5: Jul 17 '05

re: Using PHP to compile uploaded sourcecode with cygwins gcc?


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: dvdmandt@hotmail.com
Mail: dvdmandt@telia.com
"Janwillem Borleffs" <jwb@jwbfoto.demon.nl> skrev i meddelandet
news:3f6ce967$0$28889$1b62eedf@news.euronet.nl...[color=blue]
>
> "DvDmanDT" <dvdmandt@telia.com> schreef in bericht
> news:LI1bb.29418$dP1.84791@newsc.telia.net...[color=green]
> > 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[/color][/color]
some[color=blue][color=green]
> > reason, it seems like that doesn't happend from Apache/PHP/Perl.. The[/color][/color]
only[color=blue][color=green]
> > 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):
> >[/color]
>
> 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
>
>
>[/color]


Closed Thread