command line plugin added.
This commit is contained in:
parent
55d2118740
commit
14d9f54e3d
|
@ -0,0 +1,87 @@
|
|||
package org.bench4q.agent.plugin.basic;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
import org.bench4q.agent.plugin.Behavior;
|
||||
import org.bench4q.agent.plugin.Plugin;
|
||||
|
||||
@Plugin("CommandLine")
|
||||
public class CommandLinePlugin {
|
||||
private String standardOutput;
|
||||
private String standardError;
|
||||
|
||||
public String getStandardOutput() {
|
||||
return standardOutput;
|
||||
}
|
||||
|
||||
private void setStandardOutput(String standardOutput) {
|
||||
this.standardOutput = standardOutput;
|
||||
}
|
||||
|
||||
public String getStandardError() {
|
||||
return standardError;
|
||||
}
|
||||
|
||||
private void setStandardError(String standardError) {
|
||||
this.standardError = standardError;
|
||||
}
|
||||
|
||||
public CommandLinePlugin() {
|
||||
|
||||
}
|
||||
|
||||
@Behavior("Command")
|
||||
public boolean command(String command) {
|
||||
try {
|
||||
final Process process = Runtime.getRuntime().exec(command);
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getInputStream()));
|
||||
String streamline = "";
|
||||
try {
|
||||
setStandardOutput("");
|
||||
while ((streamline = reader.readLine()) != null) {
|
||||
setStandardOutput(getStandardOutput()
|
||||
+ streamline
|
||||
+ System.getProperty("line.separator"));
|
||||
}
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
new Thread() {
|
||||
public void run() {
|
||||
try {
|
||||
BufferedReader reader = new BufferedReader(
|
||||
new InputStreamReader(process.getErrorStream()));
|
||||
String streamline = "";
|
||||
try {
|
||||
setStandardError("");
|
||||
while ((streamline = reader.readLine()) != null) {
|
||||
setStandardError(getStandardError()
|
||||
+ streamline
|
||||
+ System.getProperty("line.separator"));
|
||||
}
|
||||
} finally {
|
||||
reader.close();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.start();
|
||||
process.waitFor();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue