@@ -24,7 +24,7 @@ public class TerminalPlugin extends CordovaPlugin {
2424 private static final String LOG_TAG = "TerminalPlugin" ;
2525 private CallbackContext terminalCallbackContext = null ;
2626
27- private int ProcessCode = 1 ;
27+ private int ProcessCode = 1000 ;
2828
2929 @ Override
3030 public boolean execute (String action , JSONArray data , CallbackContext callbackContext ) throws JSONException {
@@ -33,17 +33,23 @@ public boolean execute(String action, JSONArray data, CallbackContext callbackCo
3333 String cmd = data .getString (0 );
3434 JSONObject envp = data .getJSONObject (1 );
3535 String cwd = data .getString (2 );
36+ boolean printError = data .getBoolean (3 );
3637
3738 this .terminalCallbackContext = callbackContext ;
3839 String [] commands = {"su" , "-p" , "-c" , cmd };
3940
41+
4042 cordova .getThreadPool ().execute (() -> {
4143 try {
42- run (envp , cwd , commands );
43- callbackContext .error (ProcessCode );
44+ if (run (envp , cwd , commands )) {
45+ callbackContext .error (ProcessCode );
46+ }
4447 } catch (IOException | JSONException e ) {
45- callbackContext .error (500 );
4648 e .printStackTrace ();
49+ if (printError ) {
50+ updateTerminal (e .toString ());
51+ }
52+ callbackContext .error (500 );
4753 }
4854 });
4955 return true ;
@@ -58,7 +64,7 @@ public boolean execute(String action, JSONArray data, CallbackContext callbackCo
5864
5965 }
6066
61- public void run (JSONObject envp , String cwd , String ... command ) throws IOException , JSONException {
67+ public boolean run (JSONObject envp , String cwd , String ... command ) throws IOException , JSONException {
6268 ProcessBuilder pb = new ProcessBuilder (command ).redirectErrorStream (true );
6369 if (envp != null ) {
6470 Map <String , String > m = pb .environment ();
@@ -77,6 +83,8 @@ public void run(JSONObject envp, String cwd, String... command) throws IOExcepti
7783 } catch (Exception e ) {
7884 ProcessCode = 500 ;
7985 }
86+
87+ return !process .isAlive ();
8088 }
8189
8290 private void updateTerminal (String line ) {
0 commit comments