groovy-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Keegan Witt (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (GROOVY-7545) Incorrect handling of quotes in executed strings
Date Thu, 20 Aug 2015 19:05:45 GMT

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

Keegan Witt edited comment on GROOVY-7545 at 8/20/15 7:04 PM:
--------------------------------------------------------------

This isn't a Groovy bug.  Compile & run this and you'll observe the same behavior

{code:java}
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Process p = Runtime.getRuntime().exec("/bin/sh -c 'echo test'");
        String line;
        BufferedReader in = new BufferedReader(new InputStreamReader(p.getInputStream()));
        while ((line = in.readLine()) != null)
            System.out.println(line);
        in.close();
        in = new BufferedReader(new InputStreamReader(p.getErrorStream()));
        while ((line = in.readLine()) != null)
            System.err.println(line);
        in.close();
        p.waitFor();
    }
}
{code}

There's several [discussions|https://www.google.com/search?q="Runtime.getRuntime().exec"+quote]
about this.  [This one|http://stackoverflow.com/questions/161859/using-quotes-within-getruntime-exec]
goes into some detail.

The only thing Groovy could try to do is tokenize out your string parts for you.  But I don't
see how you could intelligently make that determination programmatically.


was (Author: keegan):
This isn't a Groovy bug.  Compile & run this and you'll observe the same behavior

{code:java}
public class Main {
    public static void main(String[] args) throws Exception {
        ProcessBuilder processBuilder = new ProcessBuilder("sh -c 'echo test'");
        processBuilder.redirectOutput(ProcessBuilder.Redirect.INHERIT);
        processBuilder.redirectError(ProcessBuilder.Redirect.INHERIT);
        Process process = processBuilder.start();
    }
}
{code}

There's several [discussions|https://www.google.com/search?q="Runtime.getRuntime().exec"+quote]
about this.  [This one|http://stackoverflow.com/questions/161859/using-quotes-within-getruntime-exec]
goes into some detail.

The only thing Groovy could try to do is tokenize out your string parts for you.  But I don't
see how you could intelligently make that determination programmatically.

> Incorrect handling of quotes in executed strings
> ------------------------------------------------
>
>                 Key: GROOVY-7545
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7545
>             Project: Groovy
>          Issue Type: Bug
>    Affects Versions: 2.4.0
>            Reporter: Pavel
>
> {code}
> cat execute.bug.groovy
> #!/bin/env groovy
> String cmd = "sh -c 'echo test' "
> println "cmd: $cmd"
> def proc = cmd.execute()
> proc.waitForProcessOutput(System.out, System.err)
> {code}
> {code}
> $ LANG=en_US.utf8 ./execute.bug.groovy
> cmd: sh -c 'echo test' 
> test': -c: line 0: unexpected EOF while looking for matching `''
> test': -c: line 1: syntax error: unexpected end of file
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message