diff --git a/builtin/grep.c b/builtin/grep.c index f6657afed7..a5373a473b 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -576,8 +576,9 @@ static void run_pager(struct grep_opt *opt, const char *prefix) argv[i] = path_list->items[i].string; argv[path_list->nr] = NULL; - if (prefix) - chdir(prefix); + if (prefix && chdir(prefix)) + die("Could not chdir(%s)", prefix); + execvp(argv[0], argv); error("Could not run pager %s: %s", argv[0], strerror(errno)); }