Executing an exiftool command inside a .bat file - batch-file

I found the following command line expression for exiftool here: Extract thumbnail from jpeg file
exiftool -a -b -W %d%f_%t%-c.%s -preview:all YourFileOrDirectory
The command works great on the command line, but when ran in the following batch program it seems the percent signs are misinterpreted and I'm not sure how to get it to be accept it. Can someone show me how to write this command for batch.
:: This exif command will create a file in the same directory as the one
:: where the original photo is located that contains all the thumbnail
:: images contained in the file's exif data. The exact path to the original
:: must be specified in this command.
cd\
exiftool -a -b -W %d%f_%t%-c.%s -preview:all c:\users\cher\pictures\one.jpg
pause

See exiftool FAQ 27
In a Windows .BAT file the "%" character is significant, so all "%" characters in ExifTool commands must be changed to "%%".

Related

7-zip command line - Incorrect wildcard type marker

I'm using 7-zip 15.14 64-bit on Windows 10. I have a batch file that compiles a game I'm working on, only problem is I get an error about an "Incorrect wildcard type marker". Here is the line of code taken right from the batch file.
"%ProgramFiles%\7-Zip\7z.exe" a "%expt%\Game_Win.exe" "%expt%\Win\*" -x!*.m4a -sfx -mx9 -y
Note that I do have symbolic links in the directory I'm trying to compress.
It sounds like you have enabledelayedexpansion turned on.
With this mode, ! symbols have special meaning, and to make matters more interesting, there are two parse passes on each line, meaning you'll need to double escape them to have the symbol pass through to the target application:
echo "%ProgramFiles%\7-Zip\7z.exe" a "%expt%\Game_Win.exe" "%expt%\Win\*" -x^^!*.m4a -sfx -mx9 -y

How to pass commands in a text file to an EXE running through the command line with batch?

I have a text file with lots of commands in it and I want to sent those commands to a software called thermocal. It is a console application. I found the command below, but it doesn't work for me.
Do I need to put this .exe file in the same folder of the batch file to make it work or any thing else?
type somefile.txt | Thermocal.exe
Batch scripts can be considered as a collection of lines you could also type in a command line prompt one after another. With respect to this it might be helpful for you, to play with cmd in order to get a feeling for what is happening.
About starting thermocal: Assuming thermocal is not part of PATH then the batch file either needs to change the current directory to the one with termocal.exe. Alternatively you might be able to call thermocal.exe with adding a path like C:\ProgramFiles\Thermocal\thermocal.exe . Play with cmd to find out, what works and what doesn't
When you are able to start thermocal from the command line prompt window, you can start experimenting with the call. You will probably end of with something like this in your command line window:
C:\ProgramFiles\Thermocal> thermocal argument1 argument 2
If this works, you can start with batch programming :)
Assuming your arguments are stored in somefile.txt like this:
argument1 argument 2
TYPE does nothing more than printing a file:
TYPE somefile.txt
Now you need to use the result of the output as command line arguments:
for /f %%i in ('type somefile.txt') do (thermocal.exe %%i)

Creating a dynamic .bat file

I was wondering if I could get some help with regards to writing a batch file that could take user input. (Or guidance if a batch file is not the way to go.)
I usually have a task that I do by opening CMD, navigating to a specific folder and running the following command
rda -v 848 -i "C:\me\rda-tools-1.7.0.Ra1\Input" -o "C:\me\rda-tools-1.7.0.RC1\Output"
Now this task is repetitive, and the only thing that changes each time is the number (848 in my example).
Can you guide me on how to write a batch file that navigates to the specific folder, asks me for that 3 digit number for input and then runs the command above?
Please note I have very little knowledge on batch files.
Thanks.
You can pass parameter to a batch file.
Follow below article on how to pass parameter to a batch file
How do I pass command line parameters to a batch file?
You can pass parameters to a batch file. They're taken in sequence, from %1 to %9 (you can use more, but you have to shift them to get them into position to use). (Technically, there is a %0 - it's the full path and filename of the batch file itself.)
For example, put the following into a batch file (for instance, RunRDA.bat):
#echo off
rda -v %1 -i "C:\me\rda-tools-1.7.0.Ra1\Input" -o "C:\me\rda-tools-1.7.0.RC1\Output"
Run it from a command prompt with your version:
C:\RDA>RunRDA 848
For more information, see How to pass command line parameters to a batch file?

Assoc command not working in Windows 7

I am having a need where I want to change the default associated program for a particular file extension from the command prompt. The file that I have is of an extension .ChangeSetInfo which is basically an xml file. I want to associate "Xml Notepad 2007" as the default program for this type of extension. For that I have written a small batch file. The content is as follows
assoc .CHANGESETINFO=
ftype CHANGESETINFO File=
assoc .CHANGESETINFO=CHANGESETINFO File
ftype CHANGESETINFO File="C:\Program Files\XML Notepad 2007\XmlNotepad.exe"
When I execute this batch file then it seems that everything is working fine as I am not getting any error message. But after that when I double click on the file with extension .ChangeSetInfo then the xmlnotepad program is launched but the file is not getting open. But the file is shown properly if I use the File Open option from the Xml Notepad window.
Can somebody please help me on this?
I am using Windows 7 Professional Service Pack 1. I am also using the administrator account on this system.
If you use assoc .doc on your system, it should return something like Word.Document.8. Typing ftype Word.Document.8 produces something like
Word.Document.12="C:\Program Files (x86)\Microsoft Office\Office15\WINWORD.EXE" /n "%1" /o /o "%u"
The "%1" indicates that it should open the file passed as the first parameter on the command line. The quotes around it make sure that any embedded spaces in that filename are not interpreted as command separators.
Therefore, the solution to your issue would be to change the ftype statement to do the same:
ftype CHANGESETINFO File="C:\Program Files\XML Notepad 2007\XmlNotepad.exe" "%1"
As a note: If it were me, I'd change both assoc and ftype to use ChangeSetInfoFile, both because it's easier to read and to remove the embedded space between "CHANGESETINFO" and "File".

Compare output of "DOS" command to something

(by DOS I mean windows cmd.exe - I don't want to enforce powershell or similar on the end user)
I want to run a command line file that prints output to CON / the screen.
I want to capture that output and compare it to an expected output.
... in a .bat / .cmd file?
Specifically, the identify command of ImageMagick, and I want to run this over +- 300 files and compare the actual sizes to expected sizes.
example output:
$ identify rose.jpg
rose.jpg JPEG 640x480 sRGB 87kb 0.050u 0:01
If I understand the question correctly, you want to run the identify command on all the jpg files in a directory and capture the output of that command into a text file for later comparison. The comparison however is not part of the spec?
Something like the line below should do that job. Just run it from the folder the jpg files are located:
for /R %%X in (*.jpg) do identify %%X >> PicInfo.txt
This will capture the rose.jpg JPEG ... line for every .jpg file you have in the directory (and subdirectories thanks to '/R') that you run the command in and append it to the file PicInfo.txt.
You can call your identify program with a symbol that redirects console output to a file, which is the > character. Something like:
identify rose.jpg > myoutput.txt
Additionally, the >> will append output to what is already in the file. So using
identify rose.jpg >> myoutput.txt
...should create one file with all your output.
You can then use the DOS COMP command, which compares the contents of two files. The syntax is:
COMP [data1] [data2] [/D] [/A] [/L] [/N=number] [/C] [/OFF[LINE]]
Which you could also redirect to an output file using the > symbol.

Resources