Page 1 of 2

Help php exec, system function for compile javac or java

Posted: Mon Jun 14, 2004 3:29 am
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

Posted: Mon Jun 14, 2004 3:55 am
by feyd
have you tried:

Code: Select all

exec("javac $filename", $output);
print_r($output);

Posted: Mon Jun 14, 2004 4:14 am
by antonycsf
<?php
$filename = "HelloWorld.java";
exec("javac $filename", $output);

print_r($output);
?>



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

Array()

Posted: Mon Jun 14, 2004 4:26 am
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); 
}

?>

Posted: Mon Jun 14, 2004 4:41 am
by antonycsf
result :


Array(
)

Array(
)

Posted: Mon Jun 14, 2004 4:46 am
by feyd
stupid question: are you sure HelloWorld outputs something?

have you checked php's error log? (defaults to server's, last I saw)

Posted: Mon Jun 14, 2004 4:46 am
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!

Posted: Mon Jun 14, 2004 4:48 am
by antonycsf
sorry where can i find the error log !! I am not familiar with php and linux ^^!

Posted: Mon Jun 14, 2004 4:53 am
by feyd
/your/apache/path/logs/error_log I believe.. is java's permissions set for all users to execute? (chmod)

Posted: Mon Jun 14, 2004 4:56 am
by antonycsf
sorry I am using root accout!!
and is it the error_log at [/var/log/httpd/error_log]

Posted: Mon Jun 14, 2004 4:58 am
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' ?

Posted: Mon Jun 14, 2004 5:01 am
by antonycsf
where and how to set the permissions to apache to run java ??

Posted: Mon Jun 14, 2004 5:05 am
by feyd

Posted: Mon Jun 14, 2004 5:13 am
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 ]

Posted: Mon Jun 14, 2004 5:31 am
by feyd
I think so, sorta.. not too sure.. I'm sure someone else knows more about this than me here...