0

I can get image size with this code if I run direct cmd:

identify -format "%wx%h" E:\Image.jpg

(the result = 640x480)

However, if I put this code in a bat file,

@echo off
identify -format "%wx%h" E:\Image.jpg

it doesn't work. so, (the result = h) ??

How can I do this. Thanks...

Kenshin
  • 159
  • 1
  • 1
  • 9
  • 2
    A script interprets `%wx%` as a (probably not defined) variable and replaces it with its value (probably nothing). The command line parser is slightly different: it keeps the literal `%xw%` when the variable is not defined. In a batch script. double the `%` to `%%` to escape them (treat them as a literal `%`): `identify -format "%%wx%%h" E:\Image.jpg` – Stephan Feb 05 '23 at 12:58
  • 2
    [in case, you are interested in the details](https://stackoverflow.com/questions/4094699/how-does-the-windows-command-interpreter-cmd-exe-parse-scripts?r=Saves_AllUserSaves), but be warned - it's hard stuff. – Stephan Feb 05 '23 at 13:03

1 Answers1

1

Switch % to %% in a Batchfile. Your code should be something like: identify -format "%wx%h" E:\Image.jpg

Chaos
  • 15
  • 8