*/
public static byte[] execIntoByteArray(String command) throws IOException {
File commandOutput = File.createTempFile("mircmd", "");
- int exitStatus;
try {
- // WARNING: unix specific
- exitStatus = Runtime.getRuntime().exec(new String[]{
- "/bin/sh", "-c",
- command + " " +
- ">" + commandOutput.getAbsolutePath()
- }).waitFor();
- }
- catch (InterruptedException e) {
- throw new IOException(e.toString());
+ int exitStatus;
+ try {
+ // WARNING: unix specific
+
+ exitStatus = Runtime.getRuntime().exec(new String[]{
+ "/bin/sh", "-c",
+ command + " " +
+ ">" + commandOutput.getAbsolutePath()
+ }).waitFor();
+ }
+ catch (InterruptedException e) {
+ throw new IOException(e.toString());
+ }
+ if (exitStatus != 0) {
+ throw new IOException("command exit satus:" + exitStatus);
+ }
+ return FileRoutines.readFileIntoByteArray
+ (commandOutput.getAbsoluteFile());
}
- if (exitStatus != 0) {
- throw new IOException("command exit satus:" + exitStatus);
+ finally {
+ commandOutput.delete();
}
- byte[] result = FileRoutines.readFileIntoByteArray
- (commandOutput.getAbsoluteFile());
- commandOutput.delete();
- return result;
}
/**
"/bin/sh", "-c", command
});
Reader errorStreamReader = new InputStreamReader(process.getErrorStream());
- ReaderLogger logger = new ReaderLogger(errorStreamReader, new LoggerWrapper("Utility"));
+ ReaderLogger logger =
+ new ReaderLogger(errorStreamReader, new LoggerWrapper("Utility"));
+
new Thread(logger).start();
Reader outputStreamReader = new InputStreamReader(process.getInputStream());
}
catch (IOException e) {
}
+
writer.close();
try {
reader.close();