ack3 icon indicating copy to clipboard operation
ack3 copied to clipboard

Ack hangs when used in conjunction with ssh in a single line command

Open stephenostermiller opened this issue 7 years ago • 6 comments

ack hangs when used as an argument to ssh host:

$ ssh host ack root /etc/passwd

Hangs until you press ctrl-c. Normal grep does not suffer from this problem:

$ ssh host grep root /etc/passwd
root:x:0:0:root:/root:/bin/bash

A workaround appears to be to use the --nofilter argument. It isn't clear to me exactly what it does, but I tried it because I thought that ack might be waiting for STDIN and the man page mentioned that ack treats STDIN differently with the flag:

$ ssh host ack --nofilter root /etc/passwd
root:x:0:0:root:/root:/bin/bash

Reported against

ack 2.20
Running under Perl 5.26.0 at /usr/bin/perl

stephenostermiller avatar Jan 12 '18 21:01 stephenostermiller

After reading a couple of other reports that mention nofilter I think I have a better handle on what is going on.

  • https://github.com/beyondgrep/ack2/pull/502
  • https://github.com/beyondgrep/ack2/issues/500

Ack only ignores STDIN when it detects a TTY. Most command line programs use the presence of a TTY for being interactive or not.

Ack does not use the presence of file arguments as a trigger as to whether to ignore STDIN or not. Grep ignore STDIN whenever it has file arguments.

Ack developers have wanted to support using both a file argument and STDIN at the same time and refer to reading from STDIN as "filtering".

The --nofilter option turns off processing from STDIN even when no TTY is detected. (The option would be clearer to me as --[no]stdin.)

A proposal was made to remove the --nofilter option and turn off STDIN when there are file arguments. The compromise to allow both file arguments and STDIN would be to use - as an additional argument that indicates to also read from STDIN.

Based on this analysis, there is another workaround which is to have SSH fake a tty:

$ ssh -t host ack root /etc/passwd
root:x:0:0:root:/root:/bin/bash
Connection to host closed.

None of the workarounds are compelling to me because they involve obscure command line flags that need to be memorized.

stephenostermiller avatar Jan 12 '18 21:01 stephenostermiller

Also reading from both STDIN and a file doesn't appear to work. If you use ctrl-d to close STDIN after running ack, ack just exits without processing the file arguments.

That can be tested locally using the following command and then pressing ctrl-d. The expected output is not shown:

ack --filter root /etc/passwd

stephenostermiller avatar Jan 12 '18 21:01 stephenostermiller

The option would be clearer to me as --[no]stdin.

I've thought about that, too.

Note that there have been problems with expectations of ack's handling of stdin since the dawn of time. I'm almost tempted to have to make the user have to explicitly pass a flag to use ack as a filter on stdin.

petdance avatar Jan 12 '18 21:01 petdance

Indeed, you can't read from both STDIN and a regular file.

petdance avatar Jan 12 '18 21:01 petdance

I'm seriously considering removing the implicit "figure out if ack is being a filter" or not. See the ticket referenced just above in the ack3 queue.

petdance avatar Jan 12 '18 21:01 petdance

:link:

infinitoparra avatar Dec 19 '19 05:12 infinitoparra