Skip to content

Rake::FileUtils#sh and #ruby has sematics different from that of Kernel#spawn #43

@VorontsovIE

Description

@VorontsovIE

Hello!
I was trying to redirect shell command output using rake's #sh, or #ruby. Documentation told me, that semantics is the same as Kernel#exec has (and it is the same as Kernel#spawn). So I tried to use:

ruby('-e', 'puts "hello world"', out: './tst.out' )

But actually semantic differs: FileUtils#sh removes the last argument to check its :verbose and :noop keys, so it removes redirection keys. I found a solution, which is not much more difficult:

ruby('-e', 'puts "hello world"', {out: './tst.out'}, {})

I'm not sure if it is possible and reasonable to fix behavior at a moment, but I think it's worth being noted in a documentation. Redirection to a file is a very common task when you rewrite bash scripts into rake, so an example would be very useful.

Also I'd appreciate if you describe how sh with separate ARGV arguments can be used for piping several commands.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions