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

Android开发片段–JAVA执行LInux脚本

/*
	 * シェルスクリプトを運行
	 */
	public String exec(String command) {
		StringBuffer output = new StringBuffer();
		Log.d("exec", command);
		try {
			Process process = Runtime.getRuntime().exec(command);
			DataInputStream stdout = new DataInputStream(
					process.getInputStream());
			String line;
			while ((line = stdout.readLine()) != null) {
				output.append(line).append('\n');
			}
			process.waitFor();
		} catch (Exception e) {
			PACERUtil.setLog("JAVA-ERROR", versionOld, "SHELL ERROR", storeCD, IP, macAddress);
			finish();
		}
		return output.toString();
	}
?