Open richq opened 9 years ago
I'm running into this problem too. Perhaps a solution would just be to provide an argument to force not search_stream mode or something.
@fiddlerwoaroof that flag is effectively --vimgrep, which is what I use for now when running ag from a crontab.
In ag 2.1.0 (on Fedora), as well as built from current master (2.2.0+), adding .
also works to disable stdin pipe auto-detection: foo | ag [--OPTS] PATTERN .
Peeking at the code, this was supposed got fixed by #58. This issue is 3 years newer than that fix, but I just tested master, so I think this can be closed.
Only when you don't specify any paths to search, ISPIPE check determines stdin vs current directory.
I just experienced a similar problem - adding a path did not fix it, but using --vimgrep
worked.
I can reproduce it by using entr -r
, which closes stdin as well:
# the first ag -l is just to give entr something to work with
# the second ag -l is important
# shows no files
ag -l | entr -r ag -l
# shows no files
ag -l | entr -r ag -l .
# this works
ag -l | entr -r ag -l --vimgrep
ag --version
ag version 2.2.0
Features:
+jit +lzma +zlib
I don't think this is fixed.
If I write a script with ag in it to find which files have "foo" in them:
and run that from a shell
/home/richq/checkag.sh > /tmp/checkag.log 2>&1
then I get results as expected in the /tmp/checkag.log file:etc. But if I run this exact line from a cron job it doesn't output any results. This used to work - a script I have in my crontab stopped working when I updated ag recently from 0.29 to the latest release.
I git-bisected the problem down to commit df5d456 Fix --count functionality to work with --nofilename. Indeed if I add --vimgrep to the ag command line it spits out results again from the cron job. I'm running Arch Linux, bash shell, cron is cronie 1.5.0. To reproduce the problem I had this line in my crontab to run the test script every minute and monitor the results:
As I say, ag -l works fine from the command line, and that cron-line works too when run interactively.
Debugging a bit, I found that the reason for this is that in src/options.c, around line 316 it checks S_ISFIFO on stdin, and apparently when run from cron this returns 1, it is a pipe. This sets opts.search_stream to 1 even though we aren't really searching a stream, just that stdin is not there as the shell isn't interactive. Then around line 669 it sets opts.print_path = PATH_PRINT_NOTHING since it is in search_stream mode, which later on filters out the path printing as seen in the "regression" bisection. I am not sure what the fix is for this though, probably the pipe/file/stdin detection needs tweaking (technical term, heh).