package com.fd.test; import java.io.*; /** * Created by Owen on 2019/10/31 0031 14:49 */ public class cmd { public static void main(String[] args) { // String result = exeCmd(); exeCmdMulti_1(); } public static String exeCmd() { String command = "ifconfig"; String result = ""; try { String[] cmd = new String[]{"/bin/sh", "-c", command}; Process ps = Runtime.getRuntime().exec(cmd); BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream())); StringBuffer sb = new StringBuffer(); String line; while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } result = sb.toString(); System.out.println("result: " + result); } catch (Exception e) { e.printStackTrace(); } return result; } public static String exeCmdMulti() { String result = ""; String command = "ifconfig;ls"; try { String[] cmd = new String[]{"/bin/sh", "-c", command}; Process ps = Runtime.getRuntime().exec(cmd); BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream())); StringBuffer sb = new StringBuffer(); String line; while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } result = sb.toString(); System.out.println("result: " + result); } catch (Exception e) { e.printStackTrace(); } return result; } public static String exeCmdMulti_1() { String result = ""; String command = "slpk2vts --input /var/vts/input/Production_13.slpk --output /root/java/test/test_13 --tilesetId test_13 --referenceFrame melown2015"; try { String[] cmd = new String[]{"/bin/sh", "-c", command}; Process ps = Runtime.getRuntime().exec(cmd); BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream())); StringBuffer sb = new StringBuffer(); String line; while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } result = sb.toString(); System.out.println("result: " + result); } catch (Exception e) { e.printStackTrace(); } return result; } }