Trouble registering a variable

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jonathanjohnson100
Posts: 2
Joined: 04 May 2014 18:07

Trouble registering a variable

#1 Post by jonathanjohnson100 » 04 May 2014 19:59

I want to get the width and height from imagemagick

I'm having trouble doing this

I have this:

Code: Select all

set /a w=`identify -format "%w" bmw.png`

I got this in an example I got googling
I've tried without the backtick characters as well

I get an operator missing error

I just wanted to check if I was doing something wrong in DOS?
If it's imagemagick, then at least I know I need to look that up

Thanks in advance


JJ

Squashman
Expert
Posts: 4486
Joined: 23 Dec 2011 13:59

Re: Trouble registering a variable

#2 Post by Squashman » 05 May 2014 06:11

Batch is not like Unix based shells. You need to use a FOR /F just like you did in your other post with the DIR command.

Compo
Posts: 600
Joined: 21 Mar 2014 08:50

Re: Trouble registering a variable

#3 Post by Compo » 05 May 2014 06:17

Drop the /a switch too; you are not doing arithmetic, (only setting a variable to a number); see Set /? for more info.

Something like this perhaps!

Code: Select all

@Echo off & SetLocal
If "%~1" Equ "" GoTo :EOF
If Not Exist "%~1" GoTo :EOF
(Set _inputFile=%~1)
(Set _IMDir=C:\Program Files\ImageMagicK)
PushD %_IMDir%||GoTo :EOF
For /f "UseBackQ" %%A In (`identify -format "_w=%%w\n_h=%%h" "%_inputFile%"`) Do (Set %%A)
Echo(Width is %_w%, Height is %_h%
EndLocal & Pause
Change line 5 to match your ImageMagicK installation directory then drag and drop an image onto the script to test.

Post Reply