You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Kai Hu (JIRA)" <ji...@apache.org> on 2009/01/12 11:13:59 UTC

[jira] Created: (EXEC-36) CommandLine does not work with double quote or single quote correctly

CommandLine does not work with double quote or single quote correctly
---------------------------------------------------------------------

                 Key: EXEC-36
                 URL: https://issues.apache.org/jira/browse/EXEC-36
             Project: Commons Exec
          Issue Type: Bug
    Affects Versions: 1.0
         Environment: Ubuntu 704, JDK1.6
            Reporter: Kai Hu
            Priority: Critical


Please review and run the following junit test, either apache ant or apache exec does not handle the qoute in the arguments correctly.

   @Test
    public void shouldHandleTheDoubelQuote() throws Exception {
        String commandline = "./script/jrake cruise:publish_installers "
                + "INSTALLER_VERSION=unstable_2_1 "
                + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
                + "INSTALLER_DOWNLOAD_SERVER='something'"
                + "WITHOUT_HELP_DOC=true";

        CommandLine line = CommandLine.parse(commandline);
        String[] args  = line.getArguments();

        assertThat(args[0], is("cruise:publish_installers"));
        assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1"));
        assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\""));
        assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'"));
        assertThat(args[4], is("WITHOUT_HELP_DOC=true"));
    }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (EXEC-36) CommandLine does not work with double quote or single quote correctly

Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/EXEC-36?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Siegfried Goeschl updated EXEC-36:
----------------------------------

    Attachment: ExecParseUtils.java
                ExecParseUtilsTest.java

Code based on Mitko's work in Apache Camel

> CommandLine does not work with double quote or single quote correctly
> ---------------------------------------------------------------------
>
>                 Key: EXEC-36
>                 URL: https://issues.apache.org/jira/browse/EXEC-36
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.0
>         Environment: Ubuntu 704, JDK1.6
>            Reporter: Kai Hu
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>         Attachments: ExecParseUtils.java, ExecParseUtilsTest.java
>
>
> Please review and run the following junit test, either apache ant or apache exec does not handle the qoute in the arguments correctly.
>    @Test
>     public void shouldHandleTheDoubelQuote() throws Exception {
>         String commandline = "./script/jrake cruise:publish_installers "
>                 + "INSTALLER_VERSION=unstable_2_1 "
>                 + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
>                 + "INSTALLER_DOWNLOAD_SERVER='something'"
>                 + "WITHOUT_HELP_DOC=true";
>         CommandLine line = CommandLine.parse(commandline);
>         String[] args  = line.getArguments();
>         assertThat(args[0], is("cruise:publish_installers"));
>         assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1"));
>         assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\""));
>         assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'"));
>         assertThat(args[4], is("WITHOUT_HELP_DOC=true"));
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (EXEC-36) CommandLine does not work with double quote or single quote correctly

Posted by "Kai Hu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/EXEC-36?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12663168#action_12663168 ] 

Kai Hu commented on EXEC-36:
----------------------------

>>> I think there is a space missing after "INSTALLER_DOWNLOAD_SERVER='something'" otherwise there is no args[4]

you are absolutely right

>>> is there really a space in "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\"", e.g. thus this define two paths '/var/lib/' and 'cruise-agent/installers'?
I just want to design a case that there is a whitespace in the argument, which makes the quotes to be necessary, do you mind to help me to change the test cases to
 "INSTALLER_PATH=\"/var/lib/cruise agent/installers\" and also change the assertion accordingly.

thanks for you quick response. cheers.

> CommandLine does not work with double quote or single quote correctly
> ---------------------------------------------------------------------
>
>                 Key: EXEC-36
>                 URL: https://issues.apache.org/jira/browse/EXEC-36
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.0
>         Environment: Ubuntu 704, JDK1.6
>            Reporter: Kai Hu
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>
> Please review and run the following junit test, either apache ant or apache exec does not handle the qoute in the arguments correctly.
>    @Test
>     public void shouldHandleTheDoubelQuote() throws Exception {
>         String commandline = "./script/jrake cruise:publish_installers "
>                 + "INSTALLER_VERSION=unstable_2_1 "
>                 + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
>                 + "INSTALLER_DOWNLOAD_SERVER='something'"
>                 + "WITHOUT_HELP_DOC=true";
>         CommandLine line = CommandLine.parse(commandline);
>         String[] args  = line.getArguments();
>         assertThat(args[0], is("cruise:publish_installers"));
>         assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1"));
>         assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\""));
>         assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'"));
>         assertThat(args[4], is("WITHOUT_HELP_DOC=true"));
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (EXEC-36) CommandLine does not work with double quote or single quote correctly

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/EXEC-36?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12702898#action_12702898 ] 

Sebb commented on EXEC-36:
--------------------------

I think the first thing to do is to document how the command-line parsing is intended to work.
Should it use the same quoting as the underlying OS, or a common scheme?
i.e. when is the parse() method going to be used?

> CommandLine does not work with double quote or single quote correctly
> ---------------------------------------------------------------------
>
>                 Key: EXEC-36
>                 URL: https://issues.apache.org/jira/browse/EXEC-36
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.0.0
>         Environment: Ubuntu 704, JDK1.6
>            Reporter: Kai Hu
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>
> Please review and run the following junit test, either apache ant or apache exec does not handle the qoute in the arguments correctly.
>    @Test
>     public void shouldHandleTheDoubelQuote() throws Exception {
>         String commandline = "./script/jrake cruise:publish_installers "
>                 + "INSTALLER_VERSION=unstable_2_1 "
>                 + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
>                 + "INSTALLER_DOWNLOAD_SERVER='something'"
>                 + "WITHOUT_HELP_DOC=true";
>         CommandLine line = CommandLine.parse(commandline);
>         String[] args  = line.getArguments();
>         assertThat(args[0], is("cruise:publish_installers"));
>         assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1"));
>         assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\""));
>         assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'"));
>         assertThat(args[4], is("WITHOUT_HELP_DOC=true"));
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (EXEC-36) CommandLine does not work with double quote or single quote correctly

Posted by "Kai Hu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/EXEC-36?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12683823#action_12683823 ] 

Kai Hu commented on EXEC-36:
----------------------------

when will this bug be fixed? is anyone looking at this one?

> CommandLine does not work with double quote or single quote correctly
> ---------------------------------------------------------------------
>
>                 Key: EXEC-36
>                 URL: https://issues.apache.org/jira/browse/EXEC-36
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.0.0
>         Environment: Ubuntu 704, JDK1.6
>            Reporter: Kai Hu
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>
> Please review and run the following junit test, either apache ant or apache exec does not handle the qoute in the arguments correctly.
>    @Test
>     public void shouldHandleTheDoubelQuote() throws Exception {
>         String commandline = "./script/jrake cruise:publish_installers "
>                 + "INSTALLER_VERSION=unstable_2_1 "
>                 + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
>                 + "INSTALLER_DOWNLOAD_SERVER='something'"
>                 + "WITHOUT_HELP_DOC=true";
>         CommandLine line = CommandLine.parse(commandline);
>         String[] args  = line.getArguments();
>         assertThat(args[0], is("cruise:publish_installers"));
>         assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1"));
>         assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\""));
>         assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'"));
>         assertThat(args[4], is("WITHOUT_HELP_DOC=true"));
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (EXEC-36) CommandLine does not work with double quote or single quote correctly

Posted by "Mitko Kolev (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/EXEC-36?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12855165#action_12855165 ] 

Mitko Kolev edited comment on EXEC-36 at 4/8/10 9:48 PM:
---------------------------------------------------------

Hello everyone,
I am using the commons-exec library in Apache Camel (the command arguments must be parsed from a URI), came up to the same problem, and had to implement the parsing myself. I did the custom command line args parsing based on the following 3 simple rules: 

* The args in the line are space-separated tokens
* If an argument has a space itself, this space can be quoted with " (double-qoute)
* If an argument should preserve the double-quotes, it is quoted two times with a double-quote

Here is [a link to to the parser|https://svn.apache.org/repos/asf/camel/trunk/components/camel-exec/src/main/java/org/apache/camel/component/exec/impl/ExecParseUtils.java] and a link to the [unit tests|https://svn.apache.org/repos/asf/camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecParseUtilsTest.java]. 

What do you think of this approach? Is it applicable to commons-exec?
 
Regards,
Mitko

      was (Author: mkolev):
    Hello everyone,
I am using the commons-exec library in Apache Camel (the command arguments must be parsed from a URI), came up to the same problem, and had to implement the parsing myself. I did the custom command line args parsing based on the following 3 simple rules: 

* The args in the line are space-separated tokens
* If an argument has a space itself, this space can be quoted with " (double-qoute)
* If an argument should preserve the double-quotes, it is quoted two times with a double-quote

Here is [a link to to the parser|https://svn.apache.org/repos/asf/camel/trunk/components/camel-exec/src/main/java/org/apache/camel/component/exec/impl/ExecParseUtils.java] and a link to the [unit tests|https://svn.apache.org/repos/asf/camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecParseUtilsTest.java]. 

What do you think of this solution? Is it applicable to commons-exec?
 
Regards,
Mitko
  
> CommandLine does not work with double quote or single quote correctly
> ---------------------------------------------------------------------
>
>                 Key: EXEC-36
>                 URL: https://issues.apache.org/jira/browse/EXEC-36
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.0
>         Environment: Ubuntu 704, JDK1.6
>            Reporter: Kai Hu
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>
> Please review and run the following junit test, either apache ant or apache exec does not handle the qoute in the arguments correctly.
>    @Test
>     public void shouldHandleTheDoubelQuote() throws Exception {
>         String commandline = "./script/jrake cruise:publish_installers "
>                 + "INSTALLER_VERSION=unstable_2_1 "
>                 + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
>                 + "INSTALLER_DOWNLOAD_SERVER='something'"
>                 + "WITHOUT_HELP_DOC=true";
>         CommandLine line = CommandLine.parse(commandline);
>         String[] args  = line.getArguments();
>         assertThat(args[0], is("cruise:publish_installers"));
>         assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1"));
>         assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\""));
>         assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'"));
>         assertThat(args[4], is("WITHOUT_HELP_DOC=true"));
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (EXEC-36) CommandLine does not work with double quote or single quote correctly

Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/EXEC-36?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12898640#action_12898640 ] 

Siegfried Goeschl commented on EXEC-36:
---------------------------------------

When using the API to build the command line incrementally (and not parsing the command line string) it is possible to recreate Kai's command line as shown in DefaultExecutorTest#testExec36_1() under Unix.

> CommandLine does not work with double quote or single quote correctly
> ---------------------------------------------------------------------
>
>                 Key: EXEC-36
>                 URL: https://issues.apache.org/jira/browse/EXEC-36
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.0
>         Environment: Ubuntu 704, JDK1.6
>            Reporter: Kai Hu
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>         Attachments: ExecParseUtils.java, ExecParseUtilsTest.java
>
>
> Please review and run the following junit test, either apache ant or apache exec does not handle the qoute in the arguments correctly.
>    @Test
>     public void shouldHandleTheDoubelQuote() throws Exception {
>         String commandline = "./script/jrake cruise:publish_installers "
>                 + "INSTALLER_VERSION=unstable_2_1 "
>                 + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
>                 + "INSTALLER_DOWNLOAD_SERVER='something'"
>                 + "WITHOUT_HELP_DOC=true";
>         CommandLine line = CommandLine.parse(commandline);
>         String[] args  = line.getArguments();
>         assertThat(args[0], is("cruise:publish_installers"));
>         assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1"));
>         assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\""));
>         assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'"));
>         assertThat(args[4], is("WITHOUT_HELP_DOC=true"));
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Issue Comment Edited: (EXEC-36) CommandLine does not work with double quote or single quote correctly

Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/EXEC-36?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12662927#action_12662927 ] 

sgoeschl edited comment on EXEC-36 at 1/12/09 2:30 AM:
----------------------------------------------------------------

Here is your re-formatted snippet

{noformat} 
@Test
public void shouldHandleTheDoubelQuote() throws Exception 
{ 
  String commandline = "./script/jrake cruise:publish_installers " 
    + "INSTALLER_VERSION=unstable_2_1 " 
    + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" " 
    + "INSTALLER_DOWNLOAD_SERVER='something'" 
    + "WITHOUT_HELP_DOC=true";
    
  CommandLine line = CommandLine.parse(commandline); 
  String[] args = line.getArguments(); 
  assertThat(args[0], is("cruise:publish_installers")); 
  assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1")); 
  assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\"")); 
  assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'")); 
  assertThat(args[4], is("WITHOUT_HELP_DOC=true")); 
}
{noformat} 

Some quick notes

+) args[0] should be "./script/jrake" and not "cruise:publish_installers"
+) mixing and matching singe and double quotes using CommandLine.parse() is not recommended (http://commons.apache.org/exec/faq.html)
+) I will add a test case to see how to generate a valid command line in your case

      was (Author: sgoeschl):
    Here is your re-formatted snippet

@Test
public void shouldHandleTheDoubelQuote() throws Exception 
{ 
  String commandline = "./script/jrake cruise:publish_installers " 
    + "INSTALLER_VERSION=unstable_2_1 " 
    + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" " 
    + "INSTALLER_DOWNLOAD_SERVER='something'" 
    + "WITHOUT_HELP_DOC=true";
    
  CommandLine line = CommandLine.parse(commandline); 
  String[] args = line.getArguments(); 
  assertThat(args[0], is("cruise:publish_installers")); 
  assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1")); 
  assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\"")); 
  assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'")); 
  assertThat(args[4], is("WITHOUT_HELP_DOC=true")); 
}

Some quick notes

+) args[0] should be "./script/jrake" and not "cruise:publish_installers"
+) mixing and matching singe and double quotes using CommandLine.parse() is not recommended (http://commons.apache.org/exec/faq.html)
+) I will add a test case to see how to generate a valid command line in your case
  
> CommandLine does not work with double quote or single quote correctly
> ---------------------------------------------------------------------
>
>                 Key: EXEC-36
>                 URL: https://issues.apache.org/jira/browse/EXEC-36
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.0
>         Environment: Ubuntu 704, JDK1.6
>            Reporter: Kai Hu
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>
> Please review and run the following junit test, either apache ant or apache exec does not handle the qoute in the arguments correctly.
>    @Test
>     public void shouldHandleTheDoubelQuote() throws Exception {
>         String commandline = "./script/jrake cruise:publish_installers "
>                 + "INSTALLER_VERSION=unstable_2_1 "
>                 + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
>                 + "INSTALLER_DOWNLOAD_SERVER='something'"
>                 + "WITHOUT_HELP_DOC=true";
>         CommandLine line = CommandLine.parse(commandline);
>         String[] args  = line.getArguments();
>         assertThat(args[0], is("cruise:publish_installers"));
>         assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1"));
>         assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\""));
>         assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'"));
>         assertThat(args[4], is("WITHOUT_HELP_DOC=true"));
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (EXEC-36) CommandLine does not work with double quote or single quote correctly

Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/EXEC-36?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12662927#action_12662927 ] 

Siegfried Goeschl commented on EXEC-36:
---------------------------------------

Here is your re-formatted snippet

@Test
public void shouldHandleTheDoubelQuote() throws Exception 
{ 
  String commandline = "./script/jrake cruise:publish_installers " 
    + "INSTALLER_VERSION=unstable_2_1 " 
    + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" " 
    + "INSTALLER_DOWNLOAD_SERVER='something'" 
    + "WITHOUT_HELP_DOC=true";
    
  CommandLine line = CommandLine.parse(commandline); 
  String[] args = line.getArguments(); 
  assertThat(args[0], is("cruise:publish_installers")); 
  assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1")); 
  assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\"")); 
  assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'")); 
  assertThat(args[4], is("WITHOUT_HELP_DOC=true")); 
}

Some quick notes

+) args[0] should be "./script/jrake" and not "cruise:publish_installers"
+) mixing and matching singe and double quotes using CommandLine.parse() is not recommended (http://commons.apache.org/exec/faq.html)
+) I will add a test case to see how to generate a valid command line in your case

> CommandLine does not work with double quote or single quote correctly
> ---------------------------------------------------------------------
>
>                 Key: EXEC-36
>                 URL: https://issues.apache.org/jira/browse/EXEC-36
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.0
>         Environment: Ubuntu 704, JDK1.6
>            Reporter: Kai Hu
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>
> Please review and run the following junit test, either apache ant or apache exec does not handle the qoute in the arguments correctly.
>    @Test
>     public void shouldHandleTheDoubelQuote() throws Exception {
>         String commandline = "./script/jrake cruise:publish_installers "
>                 + "INSTALLER_VERSION=unstable_2_1 "
>                 + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
>                 + "INSTALLER_DOWNLOAD_SERVER='something'"
>                 + "WITHOUT_HELP_DOC=true";
>         CommandLine line = CommandLine.parse(commandline);
>         String[] args  = line.getArguments();
>         assertThat(args[0], is("cruise:publish_installers"));
>         assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1"));
>         assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\""));
>         assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'"));
>         assertThat(args[4], is("WITHOUT_HELP_DOC=true"));
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (EXEC-36) CommandLine does not work with double quote or single quote correctly

Posted by "Kai Hu (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/EXEC-36?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12662997#action_12662997 ] 

Kai Hu commented on EXEC-36:
----------------------------

first, sorry for the bad format. thanks for formatting for me

+) arg[0] should not be "./script/jrake", I think "./script/jrake" should be returned from commandLine.getExecutable() or something like this.
+) I fully understand it is not recommented, but if this library is targeting for reduce the pain of dealing with command/process, then I think it is something this api need to provide, since I do not think there is any api can handle it correctly and that is part of the core-value of this api(Ant is using exactly same way to parse it, so it has the same bug)if you guys can ship with it, it will be the silver bullet for command/process.

cheers


> CommandLine does not work with double quote or single quote correctly
> ---------------------------------------------------------------------
>
>                 Key: EXEC-36
>                 URL: https://issues.apache.org/jira/browse/EXEC-36
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.0
>         Environment: Ubuntu 704, JDK1.6
>            Reporter: Kai Hu
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>
> Please review and run the following junit test, either apache ant or apache exec does not handle the qoute in the arguments correctly.
>    @Test
>     public void shouldHandleTheDoubelQuote() throws Exception {
>         String commandline = "./script/jrake cruise:publish_installers "
>                 + "INSTALLER_VERSION=unstable_2_1 "
>                 + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
>                 + "INSTALLER_DOWNLOAD_SERVER='something'"
>                 + "WITHOUT_HELP_DOC=true";
>         CommandLine line = CommandLine.parse(commandline);
>         String[] args  = line.getArguments();
>         assertThat(args[0], is("cruise:publish_installers"));
>         assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1"));
>         assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\""));
>         assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'"));
>         assertThat(args[4], is("WITHOUT_HELP_DOC=true"));
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (EXEC-36) CommandLine does not work with double quote or single quote correctly

Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/EXEC-36?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12683867#action_12683867 ] 

Siegfried Goeschl commented on EXEC-36:
---------------------------------------

I'm looking at the problem but I'm not eager to break the current command line processing otherwise I'm unable to get the release out of the door. Having said that you can still build up your command line bit by  bit using the API.

> CommandLine does not work with double quote or single quote correctly
> ---------------------------------------------------------------------
>
>                 Key: EXEC-36
>                 URL: https://issues.apache.org/jira/browse/EXEC-36
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.0.0
>         Environment: Ubuntu 704, JDK1.6
>            Reporter: Kai Hu
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>
> Please review and run the following junit test, either apache ant or apache exec does not handle the qoute in the arguments correctly.
>    @Test
>     public void shouldHandleTheDoubelQuote() throws Exception {
>         String commandline = "./script/jrake cruise:publish_installers "
>                 + "INSTALLER_VERSION=unstable_2_1 "
>                 + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
>                 + "INSTALLER_DOWNLOAD_SERVER='something'"
>                 + "WITHOUT_HELP_DOC=true";
>         CommandLine line = CommandLine.parse(commandline);
>         String[] args  = line.getArguments();
>         assertThat(args[0], is("cruise:publish_installers"));
>         assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1"));
>         assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\""));
>         assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'"));
>         assertThat(args[4], is("WITHOUT_HELP_DOC=true"));
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (EXEC-36) CommandLine does not work with double quote or single quote correctly

Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/EXEC-36?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12855182#action_12855182 ] 

Siegfried Goeschl commented on EXEC-36:
---------------------------------------

Hi Mitko,

let me have a look at it at the end of next week (I have to finish a paper at the end of next week)

Cheers,

Siegfried Goeschl

> CommandLine does not work with double quote or single quote correctly
> ---------------------------------------------------------------------
>
>                 Key: EXEC-36
>                 URL: https://issues.apache.org/jira/browse/EXEC-36
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.0
>         Environment: Ubuntu 704, JDK1.6
>            Reporter: Kai Hu
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>
> Please review and run the following junit test, either apache ant or apache exec does not handle the qoute in the arguments correctly.
>    @Test
>     public void shouldHandleTheDoubelQuote() throws Exception {
>         String commandline = "./script/jrake cruise:publish_installers "
>                 + "INSTALLER_VERSION=unstable_2_1 "
>                 + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
>                 + "INSTALLER_DOWNLOAD_SERVER='something'"
>                 + "WITHOUT_HELP_DOC=true";
>         CommandLine line = CommandLine.parse(commandline);
>         String[] args  = line.getArguments();
>         assertThat(args[0], is("cruise:publish_installers"));
>         assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1"));
>         assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\""));
>         assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'"));
>         assertThat(args[4], is("WITHOUT_HELP_DOC=true"));
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (EXEC-36) CommandLine does not work with double quote or single quote correctly

Posted by "Mitko Kolev (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/EXEC-36?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12855165#action_12855165 ] 

Mitko Kolev commented on EXEC-36:
---------------------------------

Hello everyone,
I am using the commons-exec library in Apache Camel (the command arguments must be parsed from a URI), came up to the same problem, and had to implement the parsing myself. I did the custom command line args parsing based on the following 3 simple rules: 

* The args in the line are space-separated tokens
* If an argument has a space itself, this space can be quoted with " (double-qoute)
* If an argument should preserve the double-quotes, it is quoted two times with a double-quote

Here is [a link to to the parser|https://svn.apache.org/repos/asf/camel/trunk/components/camel-exec/src/main/java/org/apache/camel/component/exec/impl/ExecParseUtils.java] and a link to the [unit tests|https://svn.apache.org/repos/asf/camel/trunk/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecParseUtilsTest.java]. 

What do you think of this solution? Is it applicable to commons-exec?
 
Regards,
Mitko

> CommandLine does not work with double quote or single quote correctly
> ---------------------------------------------------------------------
>
>                 Key: EXEC-36
>                 URL: https://issues.apache.org/jira/browse/EXEC-36
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.0
>         Environment: Ubuntu 704, JDK1.6
>            Reporter: Kai Hu
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>
> Please review and run the following junit test, either apache ant or apache exec does not handle the qoute in the arguments correctly.
>    @Test
>     public void shouldHandleTheDoubelQuote() throws Exception {
>         String commandline = "./script/jrake cruise:publish_installers "
>                 + "INSTALLER_VERSION=unstable_2_1 "
>                 + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
>                 + "INSTALLER_DOWNLOAD_SERVER='something'"
>                 + "WITHOUT_HELP_DOC=true";
>         CommandLine line = CommandLine.parse(commandline);
>         String[] args  = line.getArguments();
>         assertThat(args[0], is("cruise:publish_installers"));
>         assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1"));
>         assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\""));
>         assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'"));
>         assertThat(args[4], is("WITHOUT_HELP_DOC=true"));
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Commented: (EXEC-36) CommandLine does not work with double quote or single quote correctly

Posted by "Siegfried Goeschl (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/EXEC-36?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12663036#action_12663036 ] 

Siegfried Goeschl commented on EXEC-36:
---------------------------------------

Hi Kai,

+) yes you are right regarding the arg[0]
+) I think there is a space missing after "INSTALLER_DOWNLOAD_SERVER='something'" otherwise there is no args[4]
+) is there really a space in "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\"", e.g. thus this define two paths '/var/lib/' and 'cruise-agent/installers'? 

> CommandLine does not work with double quote or single quote correctly
> ---------------------------------------------------------------------
>
>                 Key: EXEC-36
>                 URL: https://issues.apache.org/jira/browse/EXEC-36
>             Project: Commons Exec
>          Issue Type: Bug
>    Affects Versions: 1.0
>         Environment: Ubuntu 704, JDK1.6
>            Reporter: Kai Hu
>            Assignee: Siegfried Goeschl
>            Priority: Critical
>
> Please review and run the following junit test, either apache ant or apache exec does not handle the qoute in the arguments correctly.
>    @Test
>     public void shouldHandleTheDoubelQuote() throws Exception {
>         String commandline = "./script/jrake cruise:publish_installers "
>                 + "INSTALLER_VERSION=unstable_2_1 "
>                 + "INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\" "
>                 + "INSTALLER_DOWNLOAD_SERVER='something'"
>                 + "WITHOUT_HELP_DOC=true";
>         CommandLine line = CommandLine.parse(commandline);
>         String[] args  = line.getArguments();
>         assertThat(args[0], is("cruise:publish_installers"));
>         assertThat(args[1], is("INSTALLER_VERSION=unstable_2_1"));
>         assertThat(args[2], is("INSTALLER_PATH=\"/var/lib/ cruise-agent/installers\""));
>         assertThat(args[3], is("INSTALLER_DOWNLOAD_SERVER='something'"));
>         assertThat(args[4], is("WITHOUT_HELP_DOC=true"));
>     }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.