Home > Net >  Unable to use `run` routine on complex bash command
Unable to use `run` routine on complex bash command

Time:03-07

Got this command: cd /some/dir; /usr/local/bin/git log --diff-filter=A --follow --format=%aI -- /some/dir/file | tail -1

I want to get the output from it.

Tried this:

my $proc2 = run 'cd', $dirname, ';', '/usr/local/bin/git', 'log', '--diff-filter=A', '--follow', '--format=%aI', '--', $output_file, '|', 'tail', '-1', :out, :err;

Nothing output.

Tried this:

my $proc2 = run </usr/local/bin/git -C>, $dirname, <log --diff-filter=A --follow --format=%aI -->, $output_file, <| tail -1>, :out, :err;

Git throws an error:

fatal: --follow requires exactly one pathspec

The same git command runs fine when run directly from the command line.

I've confirmed both $dirname and $output_file are correct.

git log --help didn't shed any light on this for me. Command runs fine straight from command line.

UPDATE: So if I take off the | tail -1 bit, I get output from the command in raku (a date). I also discovered if I take the pipe out when running on the command line, the output gets piped into more. I'm not knowledgeable enough about bash and how it might interact with raku's run command to know for sure what's going on.

CodePudding user response:

You need to run a separate proc for piping:

my $p = run «git -C "$dirname" log --diff-filter=A --format=%aI», :out, :err; 
my $p2 = run <tail -1>, :in($p.out), :out;
put .out.slurp: :close with $p2;

Also you don't need tail in this case, you can do:

put .out.lines(:close).tail with $p
  • Related