Gnu parallel and ack not playing nicely due to stdin, pipe

4

I'm trying to use parallel and ack together to do some searching in parallel. However, ack seems to insist on using stdin if it finds itself in a pipe, even if you give it files to search:

$ echo hello > test.txt

$ ack hello test.txt
hello

$ echo test.txt | xargs ack hello
hello

$ echo test.txt | parallel ack hello {}

# ack thinks it should be searching stdin:
$ echo test.txt | parallel ack -f {}
-

# even though parallel is indeed passing test.txt:
$ echo test.txt | parallel --dry-run ack hello {}
ack hello test.txt

What do I need to do to get ack and parallel to play nicely?

mgalgs

Posted 2014-04-28T22:35:00.540

Reputation: 1 762

1Consider running parallel --bibtex once to avoid the --no-notice. – Ole Tange – 2014-04-29T12:50:20.067

Answers

4

This happens on the current dev branch as well (9cc2407). The reason for this is that when standard input is a pipe, ack tries to be helpful and assumes you're trying to search that input stream. We've not seen this behavior before, so I've brought it up on the ack developers mailing list. In the meantime, you can use --nofilter to override ack's default behavior.

hoelzro

Posted 2014-04-28T22:35:00.540

Reputation: 56

adding --nofilter works, thanks! – mgalgs – 2014-04-29T22:07:44.013

2

The problem is due to this line in ack:

$is_filter_mode = -p STDIN;

So these two situations are treated differently in ack:

cat file | ack ...
ack < file ...

The workaround for you seem to be to add a cat:

echo test.txt | parallel cat {} \| ack hello

This works in ack 2.12.

Ole Tange

Posted 2014-04-28T22:35:00.540

Reputation: 3 034

0

I think ack is sick: Its behaviour is not deterministic, but it produces different output from time to time. Here I run the same command 100 times. 54 of them give "hello: No such file or directory". Note ack is being run by bash not by GNU Parallel.

$ seq 100 | parallel -N0 echo ack hello test.txt > test.sh
$ bash test.sh 2>&1 | sort | uniq -c
 54 hello: No such file or directory
100 hi

I can reproduce this behaviour when running this by hand 100 times:

$ ack hello test.txt
<<Sometimes:>> hello: No such file or directory
hi

Ole Tange

Posted 2014-04-28T22:35:00.540

Reputation: 3 034

hmm, I'm unable to reproduce these results. It's consistent for me. – mgalgs – 2014-04-29T19:40:02.383

I just tested on Linux Mint 15 and Debian 7.0: I still get the inconsistent results. What O/S are you running? – Ole Tange – 2014-04-29T20:11:40.163

Huh. Arch Linux. ack 2.12, perl 5.18.2. – mgalgs – 2014-04-29T20:15:10.600

I can reproduce your findings with ack 2.12. – Ole Tange – 2014-04-29T20:24:06.687