karaf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ASF GitHub Bot (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (KARAF-5568) Karaf Commands cannot have return codes
Date Fri, 02 Feb 2018 09:29:00 GMT

    [ https://issues.apache.org/jira/browse/KARAF-5568?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16350053#comment-16350053
] 

ASF GitHub Bot commented on KARAF-5568:
---------------------------------------

jbonofre closed pull request #436: [KARAF-5568] support return codes in karaf commands
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 a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
index b0e2765e52..9ee5b95de8 100644
--- a/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
+++ b/shell/core/src/main/java/org/apache/karaf/shell/impl/console/ConsoleSessionImpl.java
@@ -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) {
                 session.getConsole().println(session.format(result, Converter.INSPECT));
             }
         } catch (InterruptedException e) {
diff --git 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
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, Converter.INSPECT));
                 }


 

----------------------------------------------------------------
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:
users@infra.apache.org


> 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
(v7.6.3#76005)

Mime
View raw message