package com.perforce.integration;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class SystemCaller {
private final static int CROP = 120;
private static Logger logger = LoggerFactory.getLogger(SystemCaller.class);
public static int killAll(String args) throws Exception {
String cmd;
String os = System.getProperty("os.name").toLowerCase();
if (os.contains("win")) {
cmd = "taskkill /F /IM ";
args = args + ".exe";
} else {
cmd = "killall ";
}
return exec(cmd + args, true, false);
}
public static int exec(String args, boolean wait, boolean local)
throws Exception {
// add wrapper and args to build command
String[] command = null;
String os = System.getProperty("os.name").toLowerCase();
if (local) {
if (os.contains("win")) {
args = args.replace('\\', '/');
command = new String[] { args };
} else {
command = new String[] { args };
}
} else {
if (os.contains("win")) {
args = args.replace('\\', '/');
command = new String[] { "bash", "-c", args };
} else {
command = new String[] { "bash", "-c", args };
}
}
// log command
StringBuffer sb = new StringBuffer();
for (String a : command) {
sb.append(a + " ");
}
logger.info("running: " + sb.toString());
// run command
Process process = null;
try {
process = Runtime.getRuntime().exec(command);
} catch (IOException e) {
logger.warn("Failed to run...");
return -1;
}
// if blocking, then wait until done (flushing io)
if (wait) {
boolean error = false;
InputStreamReader stdout;
InputStreamReader stderr;
stdout = new InputStreamReader(process.getInputStream());
stderr = new InputStreamReader(process.getErrorStream());
BufferedReader bout = new BufferedReader(stdout);
BufferedReader berr = new BufferedReader(stderr);
String line;
while ((line = bout.readLine()) != null) {
logger.debug(line);
}
while ((line = berr.readLine()) != null) {
logger.debug(line);
error = true;
}
stdout.close();
stderr.close();
process.waitFor();
if (error)
return 1;
return process.exitValue();
} else {
return 0;
}
}
}
# |
Change |
User |
Description |
Committed |
|
#1
|
26953 |
Paul Allen |
Move //guest/perforce_software/p4convert to //guest/perforce_software/p4convert/main |
|
|
//guest/perforce_software/p4convert/src/test/java/com/perforce/integration/SystemCaller.java |
#2
|
14229 |
Paul Allen |
Update p4java to 15.1 and use RSH connection for Unit tests. |
|
|
#1
|
13920 |
Paul Allen |
copy part 2 (no errors) |
|
|
//guest/paul_allen/p4convert-maven/src/test/java/com/perforce/integration/SystemCaller.java |
#1
|
13878 |
Paul Allen |
Move test/ to src/test/java |
|
|
//guest/paul_allen/p4convert-maven/test/com/perforce/integration/SystemCaller.java |
#1
|
13873 |
Paul Allen |
Branching using p4convert-maven |
|
|
//guest/perforce_software/p4convert/test/com/perforce/integration/SystemCaller.java |
#1
|
9807 |
Paul Allen |
Initial import of p4-convert (from change 894340) |
|
|