Opening multiple PDF documents using batch file - windows

I am trying to open several PDF documents using a simple batch file:
ECHO OFF
CLS
cd Program Files\Adobe\Reader 9.0\Reader
Acrord32.exe C:\Users\BW1.pdf
Acrord32.exe C:\Users\BW2.pdf
Acrord32.exe C:\Users\BW3.pdf
Acrord32.exe C:\Users\BW4.pdf
Acrord32.exe C:\Users\BW5.pdf
Acrord32.exe C:\Users\BW6.pdf
EXIT
The above batch file opens the first PDF only, then waits until I close it for the next PDF file to open. How can I have all the PDF documents open at the same time? (Like going to Acrobat Reader, file->Open->xx.pdf)

Use start:
start acrord32.exe 1.pdf
start acrord32.exe 2.pdf
start acrord32.exe 3.pdf
Or even (as Johannes Rössel suggests in the comment below):
start 1.pdf
start 2.pdf
start 3.pdf
Would probably work as well (depending on your default PDF viewer).
Note that when using start you have to be careful when using quoted arguments, as the following won't work (the first quoted argument is interpreted as the title for a new console window):
start "1.pdf"
Instead you'll have to do the following:
start "" "1.pdf"
It's an annoying quirk of start, but you have to effectively supply a dummy title in this case to properly open the specified file (even though the title is unnecessary as this won't create a new console window).
A list of other available batch commands.

For me it works even without the start command. I use:
c:\path\to\my.pdf
in cmd.exe windows frequently, and it always opens Acrobat Reader (my default viewer on Windows). In a batchfile I've written to generate PDF via Ghostscript, my last two lines are:
"%ouptutpath%\%outputfile%.pdf"
"%outputpath%\%outputfile%-optimized.pdf"
which automatically opens both generated PDFs in two different Reader windows. (My %outputpath% contains spaces, the %outputfile% may also have some...)

Have you tried whether Acrobat Reader allows for more files on the commandline, ie.
start acrord32.exe 1.pdf 2.pdf 3.pdf

Thank you!
Using start did the trick. I had to use start as many times as the number of pdf documents I want to open. For some reason
start acrord32.exe 1.pdf 2.pdf 3.pdf
opens only the first document. So I guess Acrobat reader might not allow for more files on the command line.
I rally appreciate your answers.

Thanks for the above answers.
I also tried below, working fine:
start /B excel.exe "D:\my first file.xlsx" "E:\my second file.xlsx" "D:\working folder\my third file.xlsx"

For every pdf file in the specified directory, use the start command on that file:
for %f in ("C:\Users\*.pdf") do start %f
As per the Microsoft Docs:
For runs a specified command for each file in a set of files.
for {%variable|%%variable} in (set) do command [ CommandLineOptions]

This is follow up to the answer given by JSON C11 above.
I checked in Windows 10 OS, the command given as below with the error ("C:\Users*.pdf") was unexpected at this time.
for %f ("C:\Users*.pdf") do start %f
What is missing is 'in'. Correct code is...
for %f in ("C:\Users\*.pdf") do start %f
If you have a binary to open that particular type of file, and you like to open in maximized view, you can use the following code.
for %f in ("C:\Users\*.pdf") do start /max <path to binary> %f

Related

what does "/A" on the command - start "" /max "C:\Program Files Xxxxx.exe" /A "pagemode=FullScreen" "yourfile direction and name.pdf"

I tried to open a pdf file on full screen using command lines, and I've sucessfully found this command :
start "" /max "C:\Program Files Xxxxx.exe" /A "pagemode=FullScreen" "yourfile direction and name.pdf"
on this topic :
https://superuser.com/questions/433293/how-to-open-a-pdf-in-full-screen-mode-by-command-line
My question is: what does the "/A" mean? Is that specific to start command ? I don't find any references about "/A" on the start command documentation here : https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/start
Thanks
In terms of a pdf /A is a common Adobe Acrobat switch to indicate /Actions
Thus for AcroRd32.exe/Acrobat.exe it can be used as an inline command line switch.
Some other Acrobat competitors may also accept some (probably only a sub set) of those directives! hence some confusion as to which to use across applications.
For your example, it would not work in PDF-xchange as the allowable ones are
pagemode=<bookmarks|thumbs|none> – displays bookmarks or thumbnails.
The default setting is none.
Other apps use different means to switch behaviour e.g.
SumatraPDF.exe -FullScreen "yourfile directory and name.pdf"
Some of those same directives can be used at the end of a URL pointing to the PDF and should be used appended to the filename via #.
If the default PDF handler accepts them then
"file:///path/doc.pdf#page=2&view=Fit"
would be the equivalent of /A "page=2&view=Fit" "file:///path/doc.pdf"
see https://www.evermap.com/AutoBookmark/Manual/OpenParameters.htm
For a command to open msedge fullscreen with a file try
start "" msedge.exe --no-first-run --kiosk --new-window --edge-kiosk-type=fullscreen "file:///C:\path with a space\mydemo.pdf#page=2"
then work from there.

Can't open a .chm file from a batch file

I am trying to open a .chm file from a batch file.
The batch file has only this text in it :
echo off
start "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm"
If I run the batch file, the commandline opens but nothing further happens.
If I copy paste S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm in start menu/run then it does works.
If I make a shortcut with target "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm" then it also works.
So the command works everywhere, except from a batch file.
What am I doing wrong here ?
It might also be important to know that when I start it from the shortcut, or start menu/runI always get a dialog
We can't verify who created this file. Are you sure you want to open this file ?
I am using Windows 7
EDIT
My problem is not the dialog, my problem is that nothing happens when I open the chm file from a batch file
The Start command is probably seeing your doublequoted string as a title, enter Start /? at the command prompt for its usage information.
Try adding an empty title first:
#Echo Off
Start "" "S:\G.T.T\GTT-Vandemecum\Help Danny\GTT.chm"

cmd, Open file in Command Prompt shell without knowing its extension

I would like to run a file, in cmd without knowing the type (e.g. JPG, mp3, txt, mp4 and etc).
I tried to use 'start' command, but start (as far I found) need to know the full name of the file (with extension) and which program it should use to run it (e.g. VLC, notepad, photo viewer).
So, for example, instead of using C:\AI>start "VLC media player" "Bernard.avi" I want something like C:\AI>start "Bernard" to work similar.
If you are sure only one file has that filename you use a for loop to search for the file like this:
FOR %A IN ("C:\path\to\directory\filename.*") DO start %A
In your example it would be:
FOR %A IN ("C:\AI\Bernard.*") DO start %A
You can put it in a batch-script:
#echo off
FOR %%A IN ("%~1.*") DO start %%A
and give the path to the filename without extension as argument (don't forget the surrounding double quotes).
If multiple files have that filename it will open them all.
On linux terminal you could do something like this vlc Bernard.*,maybe you could try the * extension for windows.

DOS batch : Different behaviour between command line and drag and drop

I'm trying to write the first argument of a command line in a file, but it works in command line and not with drag and drop.
The very simple batch file (test_echo.cmd) is as following:
#echo OFF
echo %1 > echo_arg_in_file.txt`
On the command line,
C:\rep>test_echo.cmd "C:\rep\fichier de test.txt"`
creates a file echo_arg_in_file.txt with "C:\rep\fichier de test.txt" written inside.
But with a drag and drop of the file "C:\rep\fichier de test.txt" on the batch file, nothing happens... (the test to delete > echo_arg_in_file.txt was done before and displays well "C:\rep\fichier de test.txt")
Any explanation?
I'm not sure about your precise environment, but if I have to bet, current active directory is the problem
Replace your test_echo.cmd with
#echo off
for %%a in (.) do echo %%~fa
pause
Then execute the file both by double clicking it and by drag/drop a file. In both cases you will see the current active directory for the started cmd process.
Why is this relevant? As you have not included a path in the original file redirect, this file will be created in the current active directory that, maybe, could not be what you expect.
You can find more information here
For a quick solution,
#echo OFF
> "%~dp0\echo_arg_in_file.txt" echo %1
that will create the file in the same folder that hold the batch file
What Windows' version. Vista can't drag and drop into a command prompt for security reasons. Restricted possibilities are on later versions (cause we all whinged).
Prior to Vista it was the same as typing the file name if dragged into the window.
If talking about a shortcut each file is one parameter (use shift command to handle this).

cmd.exe doesn't terminate when using a .bat file

[Context: I'm trying to create a shortcut to a .bat file with a relative "Start in" path as roughly described here and here.]
cmd.exe supports the /c switch. According to the documentation, this should cause it to "carry out the command and then terminate."
But the switch seems to be ignored when the command is a .bat file.
For example, if you create a shortcut with the following Target (to a normal, non-bat command):
C:\Windows\System32\cmd.exe /c "START /d C:\temp\ notepad.exe test.txt"
Everything works as expected: Notepad opens and the console (shell) disappears. But if you replace the command above with a .bat file instead, like so:
C:\Windows\System32\cmd.exe /c "START /d C:\temp\ C:\test.bat"
(where test.bat contains only "notepad.exe test.txt") Notepad opens as before but the console sticks around like an unwanted friend. Why? And more to the point, How do I make it go away?
UPDATE: I know I can use wscript, as in this solution, but then I lose the option of having a custom icon (I'm stuck with the default .vbs icon).
The start command begins a new process for the batch file. The original cmd.exe then terminates, but leaves the new process, which hangs around because it's waiting for notepad.exe to terminate.
Change your bat file contents to:
start "" notepad.exe test.txt
Then your batch file will not wait for notepad to exit before continuing execution.
Another thing to try:
C:\Windows\System32\cmd.exe /c "START /d C:\temp\ C:\test.bat & exit"
The nuclear option would be to write a small program in the (compiled) language of your choice that launches the .bat file and then exits. Then you can give it a custom icon, and make it do whatever you like.
You might also take a look at Autoit from http://autoitscript.com as an alternative to batch. - the Run() command can do this kind of thing with better predictability. Since it makes an executable you can link this from a shortcut directly. You can also do a whole lot more of course, like run as a different user, insert delays or handle errors, that are hard to do with batch.
You don't need the full kit, just the Aut2EXE folder from the download will do.
BTW, build your exes without UPX compression as that leads to AV false positives.
I'm a little late but here is the answer.
The documentation for start states:
Syntax
START "title" [/D path] [options] "command" [parameters]
If command is an internal cmd command or a batch file then the command
processor is run with the /K switch to cmd.exe. This means that the
window will remain after the command has been run.
If start is used to execute a batch file, the opened cmd instance wont close.
You could also use call instead.
call C:\test.bat

Resources