Batch files only opens some files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Shohreh
Posts: 26
Joined: 26 Feb 2020 08:05

Batch files only opens some files

#1 Post by Shohreh » 11 Oct 2021 03:35

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.

Hackoo
Posts: 95
Joined: 15 Apr 2014 17:59

Re: Batch files only opens some files

#2 Post by Hackoo » 11 Oct 2021 05:52

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 ..
....
....

aGerman
Expert
Posts: 4325
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Batch files only opens some files

#3 Post by aGerman » 11 Oct 2021 10:02

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

Post Reply