java調用shell腳本並傳參

private void invokeShell(String projectDirectory, String ipaOutputDirectory, String version, String appName) {  
	try {  
		//第一個參數是sh命令,第 二個參數是腳本,從第三個參數天始,是我們要傳到腳本里的參數。  
		ProcessBuilder pb = new ProcessBuilder("/bin/sh",   
		OnlineBuildController.class.getResource("/").getFile() + "/ipa-build.sh",  
		projectDirectory,  
		"-o", ipaOutputDirectory,  
		"-v", version,  
		"-i", appName,  
		"-n");  
		Process p = pb.start();  
		try {  
			InputStreamReader ir = new InputStreamReader(p.getInputStream());     
			LineNumberReader input = new LineNumberReader(ir);      
			String line = null;      
			while ((line = input.readLine()) != null){    
				logger.info("info:" + line);//打印輸出內容  
			}      
			if(null != input){      
				input.close();      
			}  		  
			if(null != ir){      
				ir.close();      
			}   
			int extValue = p.waitFor();  
			logger.info("extValue:" + extValue);  
		} catch (InterruptedException e) {  
			e.printStackTrace();  
		}  
	} catch (IOException e) {  
		e.printStackTrace();  
	}  
} 

發佈了37 篇原創文章 · 獲贊 3 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章