I'm trying to open a batch file using Git Bash with a file path as parameter. I can grab the parameter using %1
. However, when I give it the path, I get this error:
I/O Error: Couldn't open file 'C:UsersUsernameDownloadsFile.pdf'
I run my batch like this:
count.bat C:\Users\Username\Downloads\File.pdf
I've tried replacing \
with /
in the file path, which works, but I'm going to drag'n'drop a file into command prompt, and I don't want to replace all the backslashes. Here's what I've done:
setlocal ENABLEDELAYEDEXPANSION
set variable="%1"
call set variable=%%variable:\=/%%
pdftotext %variable% -enc UTF-8 - | wc -m
That should replace \
with /
but it doesn't. I get the same output doing this versus simply doing pdftotext %1 -enc....
.
EDIT: Turns out Git Bash treats \
as an escape character. This means I can't simply type in the path without quotes around it, as it would try to escape it. I ended up using geisterfurz007's suggestion about opening cmd.exe, then do the file.bat
, which would call sh.exe
on my file.sh
file, which would THEN do the whole operation. A workaround but at least now it works using cmd.