Zend - The PHP Company




Utilities

Add Code


runJavaClass  

Type: application
Added by: abelard
Entered: 17/06/2002
Last modified: 06/12/2001
Rating: - (fewer than 3 votes)
Views: 3774
Tired of typing: "c:\pathtojava\java\ class"? So use this small app. You can even associate it with .class extension in Explorator so you can run java apps by double clicking


<?php

define
("JAVA_EXEC","c:j2sdk1.4.0binjavaw.exe");
define("PATH_SEPARATOR""\");

/* Prints out usage message
*/

function usage() {
    print "
Usagerunjavaclass.php FullClassFileName";
}

/* Finds argv and returns it, or message it can't be found */ 

function readPHPArgv()
    {
        global 
$argv;
        if (!is_array(
$argv)) {
            if (!is_array(
$_SERVER['argv'])) {
                if (!is_array(
$HTTP_SERVER_VARS['argv'])) {
                    return ("
Could not read cmd args (register_argc_argv=Off?)n");
                }
                return 
$HTTP_SERVER_VARS['argv'];
            }
            return 
$_SERVER['argv'];
        }
        return 
$argv;
    }

$argv = readPHPArgv();
if (is_string(
$argv)) {
//    print 
$argv;
    exit();
}

if(sizeof(
$argv) < 2) {
    usage();
    exit();
    }

$classFilePath = $argv[1];
$i=0;
$token = strtok($classFilePath, PATH_SEPARATOR);
while (
$token) {
//    print 
$token."rn";
    
$pathTokens[$i] = $token;
    
$token = strtok(PATH_SEPARATOR);
    
$i++;    
}

$classFile = $pathTokens[count($pathTokens)-1];

if (!(ereg("
.class$",$classFile))) {
    usage();
    exit();
    }

$class = str_replace(".class", "", $classFile);
//print 
$class."rn";
print (exec(JAVA_EXEC." ".
$class)."rn");
?>
Press Enter to continue
<?
$in = fopen("php://stdin", "r");
fread($in1);
exit();

?>



Usage Example




Rate This Script





Search



This Category All Categories