ASF GitHub Bot commented on KARAF-5568:

jbonofre closed pull request #436: [KARAF-5568] support return codes in karaf 
URL: https://github.com/apache/karaf/pull/436

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
index b0e2765e52..9ee5b95de8 100644
@@ -452,7 +452,7 @@ private CharSequence readCommand(AtomicBoolean reading) 
throws UserInterruptExce
     private void doExecute(CharSequence command) {
         try {
             Object result = session.execute(command);
-            if (result != null) {
+            if (result instanceof String) {
         } catch (InterruptedException e) {
diff --git 
index daa4ecceee..476efdac43 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommand.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/ShellCommand.java
@@ -129,6 +129,11 @@ public void run() {
                 if (result != null)
+                       if(result instanceof Integer) {
+                               // if it is an integer it's interpreted as a 
return code
+                               exitStatus = (Integer) result;
+                       }
                     // TODO: print the result of the command ?
 //                    session.getConsole().println(session.format(result, 


This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:

> Karaf Commands cannot have return codes
> ---------------------------------------
>                 Key: KARAF-5568
>                 URL: https://issues.apache.org/jira/browse/KARAF-5568
>             Project: Karaf
>          Issue Type: Improvement
>          Components: karaf-shell
>    Affects Versions: 4.1.4
>            Reporter: Johannes Utzig
>            Assignee: Jean-Baptiste Onofré
>            Priority: Major
>             Fix For: 4.2.0, 4.1.5
> I've been trying to implement proper return codes for my custom karaf 
> commands (so they can be evaluated when called via SSH) but it seems return 
> codes are currently not handled correctly.
> If an 'Action' returns an Integer, that integer is currently printed out on 
> stdout in the local shell and ignored in an SSH shell.
> I would like to submit a pull request that introduces the following changes:
>  * for SSH (ShellCommand) use the result as exitStatus if it is an integer
>  * for local shell (ConsoleSessionImpl) only print out the result it is an 
> instance of string

This message was sent by Atlassian JIRA

Reply via email to