Page 1 of 1

Batch files only opens some files

Posted: 11 Oct 2021 03:35
by Shohreh
Hello,

I'm using the following list of commands to launch an application and open documents in the same instance, ie. the application is only launched once:

Code: Select all

REM open.docs.cmd
start " " "C:\Program Files\SumatraPDF\SumatraPDF.exe" -reuse-instance "C:\Doc1.pdf"
start " " "C:\Program Files\SumatraPDF\SumatraPDF.exe" -reuse-instance "C:\Doc2.pdf"
start " " "C:\Program Files\SumatraPDF\SumatraPDF.exe" -reuse-instance "C:\Doc3.pdf"
etc.
For some reason, only some of the docs are opened and others are ignored.

It looks random, so I suspect it's a timing issue.

Any idea what it could be?

Thank you.

---
Edit: I think I found the cause. Some filenames have accents in them ("é", "à", etc.), and it causes cmd/the application to fail loading the file.

For some reason, it works when copy/pasting/running each command manually, accents and all.

Re: Batch files only opens some files

Posted: 11 Oct 2021 05:52
by Hackoo
Try to change code page in the begining of your batch script in order to read correctly unicode chars :

Code: Select all

@echo off
CHCP 65001>NUL
the rest of your code goes here ..
....
....

Re: Batch files only opens some files

Posted: 11 Oct 2021 10:02
by aGerman
Not sure if that would work. Windows apps usually don't know about UTF-8 at all, so I suspect this fails as well, Hackoo.

@Shohreh according to the letters in your post I guess your ANSI codepage is 1252. Run "info.bat" which is linked in the sticky thread to figure it out. Use CHCP to update the console codepage, just like Hackoo has shown.

Besides of that, give SumatraPDF a second to load the file before you continue with the next. So insert this between each of your START commands:

Code: Select all

>nul timeout /t 1 /nobreak
Steffen