123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- 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;
- }
- }
|