ripgrep: `--pre` doesn't work on Windows (CMD, MSYS2 bash, Powershell)
Please tick this box to confirm you have reviewed the above.
- I have a different issue.
What version of ripgrep are you using?
ripgrep 14.1.0 (rev e50df40a19)
How did you install ripgrep?
Download ripgrep-14.1.0-x86_64-pc-windows-msvc.zip from GitHub release page, unzip, add PATH.
What operating system are you using ripgrep on?
Windows 10
Describe your bug.
Read and run examples of GUIDE from top to bottom, everything is OK until the preprocess example: $ rg --pre ./preprocess 'The Commentz-Walter algorithm' 1995-watson.pdf.
What are the steps to reproduce the behavior?
- Download ripgrep-14.1.0-x86_64-pc-windows-msvc.zip from GitHub release page, unzip, add PATH.
- Download poppler-windows from https://github.com/oschwartz10612/poppler-windows/releases/, unzip, add PATH.
- Copy 1995-watson.pdf to C:/work2/rg-test-dir
- Following GUIDE, create
preprocessfile in C:/work2/rg-test-dir#!/bin/sh exec pdftotext - - - Launch MSYS2 (no matter via mintty, windows legacy console or windows terminal)
- Ensure
$PATHinclude/c/work2/rg-test-dir:/c/env/ripgrep/ripgrep-14.1.0-x86_64-pc-windows-msvc:/c/env/poppler/poppler-24.02.0/Library/bin cd /c/work2/rg-test-dir- Run
rg --pre ./preprocess 'The Commentz-Walter algorithm' 1995-watson.pdf$ rg --pre ./preprocess 'The Commentz-Walter algorithm' 1995-watson.pdf rg: 1995-watson.pdf: preprocessor command could not start: '"C:\\work2\\rg-test-dir\\./preprocess" " 1995-watson.pdf"': %1 is not a valid Win32 application. (os error 193)
What is the actual behavior?
- Run
rg --pre ./preprocess 'The Commentz-Walter algorithm' 1995-watson.pdf$ rg --pre ./preprocess 'The Commentz-Walter algorithm' 1995-watson.pdf rg: 1995-watson.pdf: preprocessor command could not start: '"C:\\work2\\rg-test-dir\\./preprocess" " 1995-watson.pdf"': %1 is not a valid Win32 application. (os error 193) - Run
rg --pre ./preprocess 'The Commentz-Walter algorithm' 1995-watson.pdf --debug$ rg --pre ./preprocess 'The Commentz-Walter algorithm' 1995-watson.pdf --debug rg: DEBUG|rg::flags::parse|crates/core\flags\parse.rs:97: no extra arguments found from configuration file rg: DEBUG|rg::flags::hiargs|crates/core\flags\hiargs.rs:1260: found hostname for hyperlink configuration: DESKTOP-OM1MD9D rg: DEBUG|rg::flags::hiargs|crates/core\flags\hiargs.rs:1270: hyperlink format: "" rg: DEBUG|rg::flags::hiargs|crates/core\flags\hiargs.rs:174: using 1 thread(s) rg: DEBUG|grep_cli::decompress|crates\cli\src\decompress.rs:502: lz4: could not find executable in PATH rg: DEBUG|globset|crates\globset\src\lib.rs:453: built glob set; 0 literals, 0 basenames, 11 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 0 regexes rg: 1995-watson.pdf: preprocessor command could not start: '"C:\\work2\\rg-test-dir\\./preprocess" "1995-watson.pdf"': %1 is not a valid Win32 application. (os error 193)
P.S.
-
If I do not set the working directory
/c/work2/rg-test-dir, it will reportrg: ./preprocess: could not find executable in PATHThis is a bit weird, although GUIDE says
preprocessmust be put in PATH. -
I also tried CMD and Powershell by the following preprocess scripts, none of them works (and with the same error).
@echo off pdftotext %1 -preprocess.ps1
$PSDefaultParameterValues['*:Encoding'] = 'utf8' Start-Process -NoNewWindow -Wait -FilePath "pdftotext.exe" -ArgumentList $Args[0], "-"
Thanks.
What is the expected behavior?
No error.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 16 (8 by maintainers)
@ltrzesniewski Thank you!!!
Ok maybe I could help a bit 🙂
Windows has essentially two functions to start processes:
CreateProcessandShellExecuteEx.The first one is the low-level API which can “only” run .exe and .bat files, while the second one is the higher-level shell API which is able to map file extensions such as .ps1 to their executables such as powershell.exe. Their behvior can be very different depending on what you’re trying to do, but Rust uses
CreateProcess.The following has been added recently to the Rust
processmodule docs:I tested it quickly, and ripgrep is able to run a .bat file with
--prebut not a .ps1 script (as that would requireShellExecuteEx, which in any case doesn’t support output redirecting so it’s a no-go).Here’s
C:\Temp\test.bat:Here’s
C:\Temp\test.ps1:And there’s also an empty file in
C:\Temp\empty.txt, just to show that the searched file content is irrelevent.Here are the results:
So you should be able to get the output from a .bat file just fine. In case it’s relevant, I compiled my ripgrep with Rust 1.78.0, which includes changes to
Commandunder Windows, so that may play a role in the results.