Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
stephenostermiller opened this issue Jan 12, 2018 · 6 comments

Comments

@stephenostermiller
Copy link

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
Copy link
Author

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

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
Copy link
Author

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

@petdance
Copy link
Collaborator

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
Copy link
Collaborator

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

@petdance
Copy link
Collaborator

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 petdance transferred this issue from beyondgrep/ack2 Sep 28, 2019
@infinitoparra
Copy link

🔗

barefootcoder added a commit to barefootcoder/common that referenced this issue Feb 11, 2024
this calls `vgrep` on all 3 major CE repos (`CE:`, `archer-boot:`, and `cheops:`
this requied some ancillary changes to `vgrep`:
-	fix for `ack` not working when called via `ssh`
--		(cf beyondgrep/ack3#259)
-	simplify the paging code
-	only spit out the spacing lines if printing to a terminal
-	try to return a proper error code
--		this isn't working yet
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants