日期:2014-05-16  浏览次数:20888 次

java调用linux shell命令
/**
	 * 调用shell命令,创建android project
	 * /home/appcan/workspace/AceBase/script
	 * workspace="$HOME/workspace"
	 */
	private void callShellAndroid(String appId)
	{
		String shpath="/home/appcan/AceBase/script/CrApro.sh";   //程序路径
		Process pid = null ;
		String[] cmd = {"bash",shpath,appId};
		try {
			pid = Runtime.getRuntime().exec(cmd);
			int wfId = pid.waitFor();
			System.out.println("pid = " + pid);
			System.out.println("pid.waitFor() = " + wfId);
			if(wfId == 0 ){
				System.out.println("Command execute result is OK !");
			}else{
				System.out.println("Command execute result is fail......");
			}
		} catch (IOException e) {
			e.printStackTrace();
		}catch (InterruptedException e) {
			e.printStackTrace();
		}
	}