+/*
+ * Copyright 2007 the original author or authors.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package org.wamblee.io;
import java.io.BufferedReader;
private static final Log LOG = LogFactory.getLog(SimpleProcess.class);
- private File _directory;
+ private File directory;
- private String[] _cmd;
+ private String[] cmd;
- private String _stdout;
- private String _stderr;
+ private String stdout;
+ private String stderr;
public SimpleProcess(File aDirectory, String[] aCmd) {
- _directory = aDirectory;
- _cmd = aCmd;
+ directory = aDirectory;
+ cmd = aCmd;
}
/**
* @return the stdout
*/
public String getStdout() {
- return _stdout;
+ return stdout;
}
/**
* @return the stderr
*/
public String getStderr() {
- return _stderr;
+ return stderr;
}
/**
private int runImpl() throws IOException {
try {
String fullcmd = "";
- for (String part: _cmd) {
+ for (String part: cmd) {
fullcmd += " " + part;
}
- LOG.debug("Executing '" + fullcmd + "' in directory '" + _directory
+ LOG.debug("Executing '" + fullcmd + "' in directory '" + directory
+ "'");
- java.lang.Process proc = Runtime.getRuntime().exec(_cmd, null, _directory);
+ java.lang.Process proc = Runtime.getRuntime().exec(cmd, null, directory);
// Read standard output and error in separate threads to avoid
// deadlock.
- StringWriter stdout = new StringWriter();
- StringWriter stderr = new StringWriter();
+ StringWriter myStdout = new StringWriter();
+ StringWriter myStderr = new StringWriter();
Thread stdoutReader = readAndLogStream("STDOUT> ", proc
- .getInputStream(), stdout);
+ .getInputStream(), myStdout);
Thread stderrReader = readAndLogStream("STDERR> ", proc
- .getErrorStream(), stderr);
+ .getErrorStream(), myStderr);
try {
proc.waitFor();
waitForReader(stdoutReader);
waitForReader(stderrReader);
- _stdout = stdout.toString();
- _stderr = stderr.toString();
+ stdout = myStdout.toString();
+ stderr = myStderr.toString();
if (proc.exitValue() != 0) {
LOG.warn("Exit value was non-zero: " + this);
@Override
public String toString() {
String fullcmd = "";
- for (String part: _cmd) {
+ for (String part: cmd) {
fullcmd += part + " ";
}
- return "process(dir = '" + _directory + "', cmd = '" + fullcmd + "')";
+ return "process(dir = '" + directory + "', cmd = '" + fullcmd + "')";
}
}