ITeye博客

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

04023129 · 2011-12-07 14:49 · Android代码片段 · 移动开发 · Markdown

/*
	 * シェルスクリプトを運行
	 */
	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();
	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。