Help php exec, system function for compile javac or java

Whether you are using Linux on the desktop or as a server, it's still good that you're using Linux. Linux related questions go here.

Moderator: General Moderators

antonycsf
Forum Newbie
Posts: 16
Joined: Mon Jun 14, 2004 3:29 am

Help php exec, system function for compile javac or java

Post by antonycsf »

Can anyone have this experience to use php code to call external compiler to compile program e.g:


<?php
exec("javac $filename > error.txt");
exec("java HelloWorld > output.txt");
?>

I can compile the program on window platform but not in linux.

In window it works.
In linux the result the is nothing.
Anyone have this experience before ??
I would like to know how to call a compiler using php [any setting on linux or apache or php]??

Thx. :oops: :oops: :oops: :oops: :oops:




Moved to Linux Forums- Infolock
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

have you tried:

Code: Select all

exec("javac $filename", $output);
print_r($output);
antonycsf
Forum Newbie
Posts: 16
Joined: Mon Jun 14, 2004 3:29 am

Post by antonycsf »

<?php
$filename = "HelloWorld.java";
exec("javac $filename", $output);

print_r($output);
?>



====================
output is :

Array()
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

and what about this?

Code: Select all

<?php 

if(!defined('_DEBUG_')) define('_DEBUG_',1);

if(_DEBUG_)
{
header('Content-type: text/plain');

ini_set('display_errors','1');
error_reporting(E_ALL);
}
$filename = "HelloWorld.java";
$last = exec("javac $filename", $output); 

if(_DEBUG_)
{
echo $last."\n";
print_r($output); 
}

$last = exec("java HelloWorld",$output); 

if(_DEBUG_)
{
echo $last."\n";
print_r($output); 
}

?>
antonycsf
Forum Newbie
Posts: 16
Joined: Mon Jun 14, 2004 3:29 am

Post by antonycsf »

result :


Array(
)

Array(
)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

stupid question: are you sure HelloWorld outputs something?

have you checked php's error log? (defaults to server's, last I saw)
antonycsf
Forum Newbie
Posts: 16
Joined: Mon Jun 14, 2004 3:29 am

Post by antonycsf »

the directory is /var/www/html/cmd/testcmd.php

do I need to set anything to do this on linux Fedora Core 2

I try the gcc comand also display the result of HelloWorld



just use the following command :
==========================
echo `gcc HelloWorld.c`;
echo `./a.out`;

it shows me the correct result a a.out is generated also

thx!
antonycsf
Forum Newbie
Posts: 16
Joined: Mon Jun 14, 2004 3:29 am

Post by antonycsf »

sorry where can i find the error log !! I am not familiar with php and linux ^^!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

/your/apache/path/logs/error_log I believe.. is java's permissions set for all users to execute? (chmod)
antonycsf
Forum Newbie
Posts: 16
Joined: Mon Jun 14, 2004 3:29 am

Post by antonycsf »

sorry I am using root accout!!
and is it the error_log at [/var/log/httpd/error_log]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

that sounds like it.. (error_log)

as for the permissions, I was talking about apache's status as running as nobody.. would it have access rights to 'java' ?
antonycsf
Forum Newbie
Posts: 16
Joined: Mon Jun 14, 2004 3:29 am

Post by antonycsf »

where and how to set the permissions to apache to run java ??
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

antonycsf
Forum Newbie
Posts: 16
Joined: Mon Jun 14, 2004 3:29 am

Post by antonycsf »

do you mean I need to enable the apache to run java

chmod who=permissions filename

chmod apache=777 /usr/java/j2sdk1.4.2_04/bin/javac

[I am not sure the java or javac <- file locate at which directory, is it something like /usr/java/j2sdk1.4.2_04/bin/javac ]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I think so, sorta.. not too sure.. I'm sure someone else knows more about this than me here...
Post Reply