php使用exec函數調用java main方法

java:`

public class Test{
	public static void main(String[] args) {
		if(args.length == 2) {
			String type = args[0];
			String value = args[1];
			String md5 = "";
			if("string".equals(type)) {
				md5 = "string:"+value;
			}else if("file".equals(type)) {
				md5 ="file:"+value;				
			}
			System.out.print(md5); //此處打印後,php可以獲取到內容
		}
	}
}

php:

<?php
$type= "string";
$value="hello world!";
$str="java TestDest ".$value." ".$key;
exec($str,$output,$retnruVal);
print_r($output); //此處會顯示java System.out.print出來的數據
?>
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章