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?

1
  • 1
    Consider running parallel --bibtex once to avoid the --no-notice.
    – Ole Tange
    Apr 29, 2014 at 12:50

3 Answers 3

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.

0
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.

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
4
  • hmm, I'm unable to reproduce these results. It's consistent for me.
    – mgalgs
    Apr 29, 2014 at 19:40
  • 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
    Apr 29, 2014 at 20:11
  • Huh. Arch Linux. ack 2.12, perl 5.18.2.
    – mgalgs
    Apr 29, 2014 at 20:15
  • I can reproduce your findings with ack 2.12.
    – Ole Tange
    Apr 29, 2014 at 20:24

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .