aboutsummaryrefslogtreecommitdiffstats
path: root/app/src/fil/libre/repwifiapp/helpers/ShellCommand.java
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/fil/libre/repwifiapp/helpers/ShellCommand.java')
-rw-r--r--app/src/fil/libre/repwifiapp/helpers/ShellCommand.java150
1 files changed, 73 insertions, 77 deletions
diff --git a/app/src/fil/libre/repwifiapp/helpers/ShellCommand.java b/app/src/fil/libre/repwifiapp/helpers/ShellCommand.java
index e2004a7..fbeb719 100644
--- a/app/src/fil/libre/repwifiapp/helpers/ShellCommand.java
+++ b/app/src/fil/libre/repwifiapp/helpers/ShellCommand.java
@@ -4,82 +4,78 @@ import java.io.IOException;
import java.io.InputStream;
public class ShellCommand {
-
- private String _cmdOut = "";
- private String _cmdTxt = "";
-
- public ShellCommand(String commandText){
- this._cmdTxt = commandText;
- }
-
-
- public int execute() throws Exception{
-
- if ( this._cmdTxt == null ){
- return -9;
- }
-
- Utils.logDebug("EXEC: " + this._cmdTxt);
-
- Process cmd = Runtime.getRuntime().exec(this._cmdTxt);
-
- InputStream os = cmd.getInputStream();
- InputStream es = cmd.getErrorStream();
-
- StringBuilder sb = new StringBuilder();
-
- sb.append(getStringFromStream(es));
- sb.append(getStringFromStream(os));
-
- int res = cmd.waitFor();
-
- //re-read the output, in case it was empty when first tried
- sb.append(getStringFromStream(es));
- sb.append(getStringFromStream(os));
-
- this._cmdOut = sb.toString();
-
- Utils.logDebug("EXITCODE: " + res);
- Utils.logDebug("OUT: " + getOutput());
-
- return res;
-
- }
-
- private String getStringFromStream(InputStream s) throws IOException{
-
- StringBuilder sb = new StringBuilder();
- while ( (s.available() > 0) ) {
- int b = s.read();
- if (b>=0){
- sb.append((char)b);
- }else{
- break;
- }
- }
-
- return sb.toString();
-
- }
-
-
- public String getOutput(){
-
- return this._cmdOut;
-
- /*String[] lastOut = Utils.readFileLines(Commons.getTempOutFile());
- if (lastOut == null){
- return this._cmdOut;
- }
-
- String fout = "";
-
- for (String s : lastOut){
- fout += s + "\n";
- }
-
- return fout;*/
-
- }
+
+ protected String _cmdOut = "";
+ protected String _cmdTxt = "";
+
+ public ShellCommand(String commandText) {
+ this._cmdTxt = commandText;
+ }
+
+ public int execute() throws Exception {
+
+ if (this._cmdTxt == null) {
+ return -9;
+ }
+
+ Utils.logDebug("EXEC: " + this._cmdTxt);
+
+ Process cmd = Runtime.getRuntime().exec(this._cmdTxt);
+
+ InputStream os = cmd.getInputStream();
+ InputStream es = cmd.getErrorStream();
+
+ StringBuilder sb = new StringBuilder();
+
+ sb.append(getStringFromStream(es));
+ sb.append(getStringFromStream(os));
+
+ int res = cmd.waitFor();
+
+ // re-read the output, in case it was empty when first tried
+ sb.append(getStringFromStream(es));
+ sb.append(getStringFromStream(os));
+
+ this._cmdOut = sb.toString();
+
+ Utils.logDebug("EXITCODE: " + res);
+ Utils.logDebug("OUT: " + getOutput());
+
+ return res;
+
+ }
+
+ protected String getStringFromStream(InputStream s) throws IOException {
+
+ StringBuilder sb = new StringBuilder();
+ while ((s.available() > 0)) {
+ int b = s.read();
+ if (b >= 0) {
+ sb.append((char) b);
+ } else {
+ break;
+ }
+ }
+
+ return sb.toString();
+
+ }
+
+ public String getOutput() {
+
+ return this._cmdOut;
+
+ /*
+ * String[] lastOut = Utils.readFileLines(Commons.getTempOutFile()); if
+ * (lastOut == null){ return this._cmdOut; }
+ *
+ * String fout = "";
+ *
+ * for (String s : lastOut){ fout += s + "\n"; }
+ *
+ * return fout;
+ */
+
+ }
}