You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aggregation-platform/src/com/platform/utils/RunCommand.java

61 lines
1.4 KiB

package com.platform.utils;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import org.apache.log4j.*;
public class RunCommand {
public static Logger log = Logger.getLogger(RunCommand.class);
public List<String> runCommandWait(String command) {
List<String> reStrings = null;
String cmds[] = { "/bin/bash", "-c", command };
try {
Process ps = Runtime.getRuntime().exec(cmds);
ps.waitFor();
BufferedReader br = new BufferedReader(new InputStreamReader(ps.getInputStream()));
reStrings = new ArrayList<String>();
String line;
while ((line = br.readLine()) != null) {
reStrings.add(line);
// System.out.println(line);
}
br = new BufferedReader(new InputStreamReader(ps.getErrorStream()));
reStrings = new ArrayList<String>();
while ((line = br.readLine()) != null) {
reStrings.add(line);
// System.out.println(line);
}
} catch (Exception e) {
log.error("0001 runCommandWait is error");
e.printStackTrace();
}
return reStrings;
}
public int runCommand(String command) {
List<String> reStrings = null;
String cmds[] = { "/bin/bash", "-c", command };
try {
Process ps = Runtime.getRuntime().exec(cmds);
} catch (Exception e) {
log.error("0002 runCommand execute " + command + " is error");
e.printStackTrace();
return -1;
}
return 1;
}
}