Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 322DB106AD for ; Thu, 20 Feb 2014 19:45:43 +0000 (UTC) Received: (qmail 60592 invoked by uid 500); 20 Feb 2014 19:45:32 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 60317 invoked by uid 500); 20 Feb 2014 19:45:27 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 60292 invoked by uid 99); 20 Feb 2014 19:45:27 -0000 Received: from arcas.apache.org (HELO arcas.apache.org) (140.211.11.28) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 20 Feb 2014 19:45:27 +0000 Date: Thu, 20 Feb 2014 19:45:27 +0000 (UTC) From: "Kevin Brown (JIRA)" To: issues@commons.apache.org Message-ID: In-Reply-To: References: Subject: [jira] [Comment Edited] (EXEC-83) Arguments with spaces lead to quotes in arguments in bash MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 [ https://issues.apache.org/jira/browse/EXEC-83?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13907388#comment-13907388 ] Kevin Brown edited comment on EXEC-83 at 2/20/14 7:45 PM: ---------------------------------------------------------- [~b.eckenfels] [~sebb@apache.org] Thanks for your replies. For now, I'm including some java code that recreates my original issue. I'll modify this code to use the ProcessBuilder/bash example above shortly. Java: {code:title=Foo.java|borderStyle=solid} @Test public void testExecutor() throws IOException { String script="/Users/kevin/foo.sh"; String arg1="100"; String arg2="kevin was here"; String arg3="three"; CommandLine commandLine = new CommandLine(script); commandLine.addArgument(arg1, false); commandLine.addArgument(arg2, true); commandLine.addArgument(arg3, false); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(null); //check for exit values ourselves System.out.println("cmdLine="+ commandLine.toString()); int exitValue = executor.execute(commandLine); System.out.println("exitValue="+ exitValue); } {code} #foo.sh being called from Java mac:~ kevin$ cat ./foo.sh #!/bin/bash echo "The number of arguments is: $#" >> ~/log.txt a=${@} count=0 for var in "$@" do echo "The length of argument '$var' is: ${#var}" >> ~/log.txt (( count++ )) done #RUN JUnit test from IDE HERE -- look at results mac:~ kevin$ cat ~/log.txt The number of arguments is: 3 The length of argument '100' is: 3 The length of argument '"kevin was here"' is: 16 The length of argument 'three' is: 5 #Compare with running from command line mac:~ kevin$ rm ~/log.txt mac:~ kevin$ /Users/kevin/foo.sh 100 "kevin was here" three mac:~ kevin$ cat ~/log.txt The number of arguments is: 3 The length of argument '100' is: 3 The length of argument 'kevin was here' is: 14 The length of argument 'three' is: 5 Notice that the 2nd argument is quoted in the first run and not in the second was (Author: kbrowncnn): [~b.eckenfels] [~sebb@apache.org] Thanks for your replies. For now, I'm including some java code that recreates my original issue. I'll modify this code to use the ProcessBuilder/bash example above shortly. Java: @Test public void testExecutor() throws IOException { String script="/Users/kevin/foo.sh"; String arg1="100"; String arg2="kevin was here"; String arg3="three"; CommandLine commandLine = new CommandLine(script); commandLine.addArgument(arg1, false); commandLine.addArgument(arg2, true); commandLine.addArgument(arg3, false); DefaultExecutor executor = new DefaultExecutor(); executor.setExitValues(null); //check for exit values ourselves System.out.println("cmdLine="+ commandLine.toString()); int exitValue = executor.execute(commandLine); System.out.println("exitValue="+ exitValue); } #foo.sh being called from Java mac:~ kevin$ cat ./foo.sh #!/bin/bash echo "The number of arguments is: $#" >> ~/log.txt a=${@} count=0 for var in "$@" do echo "The length of argument '$var' is: ${#var}" >> ~/log.txt (( count++ )) done #RUN JUnit test from IDE HERE -- look at results mac:~ kevin$ cat ~/log.txt The number of arguments is: 3 The length of argument '100' is: 3 The length of argument '"kevin was here"' is: 16 The length of argument 'three' is: 5 #Compare with running from command line mac:~ kevin$ rm ~/log.txt mac:~ kevin$ /Users/kevin/foo.sh 100 "kevin was here" three mac:~ kevin$ cat ~/log.txt The number of arguments is: 3 The length of argument '100' is: 3 The length of argument 'kevin was here' is: 14 The length of argument 'three' is: 5 Notice that the 2nd argument is quoted in the first run and not in the second > Arguments with spaces lead to quotes in arguments in bash > --------------------------------------------------------- > > Key: EXEC-83 > URL: https://issues.apache.org/jira/browse/EXEC-83 > Project: Commons Exec > Issue Type: Bug > Affects Versions: 1.2 > Environment: Java 7 & OSX > Reporter: Kevin Brown > Priority: Minor > > If I run my script directly from a bash prompt I see a different behavior than if I launch with commons-exec. This may be the nature of the beast (java Runtime-exec interacting with bash), but leads me to have to rewrite scripts to remove extraneous quotes. > Here is my script: > $ cat ./foo.sh > #!/bin/bash > echo "$@" > case I: commons-exec with no spaces ==> arguments do NOT have quotes when in bash script > cmdLine=[/opt/bmam/bin/avidcommand/write_xmp_remote.sh, 70059021, RAW-one_two_three, http://foo.com] > output (of $@): > 70059021 RAW-one_two_three http://foo.com > case II: commons-exec with spaces ==> arguments have quotes when in bash script > cmdLine=[/opt/bin/foo.sh, 70058269, "AIR-one two three", http://foo.com] > output (of $@): > 70058269 "AIR-one two three" http://foo.com > case III: execute directly from bash ==> arguments do NOT have quotes when in bash script > $./foo.sh 70058891 "one two three" http://foo.com > output (of $@): > 70058891 one two three http://foo.com -- This message was sent by Atlassian JIRA (v6.1.5#6160)