Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem executing commands with backslash #55

Open
lonsbio opened this issue Oct 20, 2014 · 2 comments
Open

Problem executing commands with backslash #55

lonsbio opened this issue Oct 20, 2014 · 2 comments

Comments

@lonsbio
Copy link
Collaborator

lonsbio commented Oct 20, 2014

From [email protected] on 2012-08-14T15:16:03Z

With single quotes:
$ bpipe run batch_merge_replicates.groovy ./otus/ggsilva/otu_table_ggsilva.qiime
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script_from_command_line: 65: unexpected char: '' @ line 65, column 24.
exec "perl -p -e 's/./_/g;' $input > $output"
^
1 error

With triple quotes:
$ bpipe run batch_merge_replicates.groovy ./otus/ggsilva/otu_table_ggsilva.qiime
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
script_from_command_line: 66: unexpected char: '' @ line 66, column 21.
perl -p -e 's/./_/g;' $input > $output

1 error

Not all commands with a backslash fail. For example, this works ok:
exec """perl -p -e 'print "Foo\n";' $input > $output"""

Original issue: http://code.google.com/p/bpipe/issues/detail?id=55

@lonsbio
Copy link
Collaborator Author

lonsbio commented Oct 20, 2014

From [email protected] on 2012-08-14T19:06:01Z

This is one of those niggling areas where nested string values get a bit problematic, partly because Groovy's evaluation of backslashes in strings differs a little bit to Bash. The problem is that Groovy intercepts the backslash and if escaped character is a 'legal' character for escaping in Groovy then it throws the error. I've been thinking about ways to deal with this or at least make it clearer to people, but it's not easy to do in a clean way.

A workaround is to use yet another kind of String syntax in Groovy, using $/ and /$ as string delimiters. Then your expression becomes:

exec($/perl -p -e 's/./_/g;' $input > $output/$)

Notice that you also end up needing brackets around the value which is unfortunate.

@lonsbio
Copy link
Collaborator Author

lonsbio commented Oct 20, 2014

From [email protected] on 2012-08-14T19:29:24Z

It's good to know. Thanks Simon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant