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.java85
1 files changed, 85 insertions, 0 deletions
diff --git a/app/src/fil/libre/repwifiapp/helpers/ShellCommand.java b/app/src/fil/libre/repwifiapp/helpers/ShellCommand.java
new file mode 100644
index 0000000..e2004a7
--- /dev/null
+++ b/app/src/fil/libre/repwifiapp/helpers/ShellCommand.java
@@ -0,0 +1,85 @@
+package fil.libre.repwifiapp.helpers;
+
+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;*/
+
+ }
+
+}