Solved

SQL xp_cmdshell errors. MSSQL, Programming, ImageMagick

Posted on 2011-09-12
8
436 Views
Last Modified: 2012-05-12
Hello experts,

I’m experiencing some trouble with xp_cmdshell in SQL.  It appears that, though I can easily call ImageMagick through the command prompt, but SQL won’t allow me to run the commands through xp_cmdshell.  

I can currently run other batch scripts, programs, and basic move and copy commands with xp_cmdshell, but not the following script:

EXEC master.dbo.xp_cmdshell 'convert "C:\TESTS\20_pg_tiff_bia.TIF" "C:\TESTS\20_pg_tiff_bia_%d.TIF"'
Errors:  Invalid Parameter - "C:\TESTS\20_pg_tiff_bia_%d.TIF"
NULL

Simplifying the expression still causes errors:
EXEC master.dbo.xp_cmdshell 'convert "C:\TESTS\20_pg_tiff_bia.TIF" "C:\TESTS\20_pg_tiff_bia2.TIF"'
Errors:  Invalid Parameter - "C:\TESTS\20_pg_tiff_bia2.TIF"
NULL

Both of these calls without issues when invoked through cmd:
convert "C:\TESTS\20_pg_tiff_bia.TIF" "C:\TESTS\20_pg_tiff_bia_%d.TIF"
convert "C:\TESTS\20_pg_tiff_bia.TIF" "C:\TESTS\20_pg_tiff_bia2.TIF"

Any ideas?
0
Comment
Question by:robthomas09
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
8 Comments
 
LVL 22

Expert Comment

by:pivar
ID: 36526065
Hi,

Can you try to use the path to convert exe?

EXEC master.dbo.xp_cmdshell 'C:\[path to ImageMagick convert binary]\convert "C:\TESTS\20_pg_tiff_bia.TIF" "C:\TESTS\20_pg_tiff_bia2.TIF"'

It might be that you have another convert on your path.

/peter
0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 36539134
If that doesn't work try it like this...

declare @shellcmd varchar(500)

set @shellcmd = 'C:\[path to ImageMagick convert binary]\convert "C:\TESTS\20_pg_tiff_bia.TIF" "C:\TESTS\20_pg_tiff_bia2.TIF"'

exec master.dbo.xp_cmdshell @shellcmd
0
 

Author Comment

by:robthomas09
ID: 36568060
No dice on either of those.  Could the VBS be stalling out, or something?
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 36568214
What vbs??  I thought you were running a program called "convert.exe"
..no?

Did you get the same error this time, or a different error?



0
 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 36568223
--Please try this...
--And make sure the files exist first.

declare @shellcmd varchar(500)

set @shellcmd = 'convert C:\TESTS\20_pg_tiff_bia.TIF C:\TESTS\20_pg_tiff_bia2.TIF'

exec master.dbo.xp_cmdshell @shellcmd
0
 

Author Comment

by:robthomas09
ID: 36568623
I'm sorry -- VBS was a workaround I tried, referring to another post: http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SQL_Server_2008/Q_27317780.html 

Assigning the shell cmd into a variable doesn't working, either, xuserx2000.  Still the exact same parameter error.
0
 
LVL 25

Accepted Solution

by:
Ron Malmstead earned 500 total points
ID: 36568739
"Invalid Parameter - C:\TESTS\20_pg_tiff_bia2.TIF"

That is an error coming from the "Convert" application.
The shellcmd is working as it is expected to and returning the output from the "convert" app.

Convert is an application built into windows to convert an HD to filesystem.. NTFS or FAT32.

Please supply the full path to imagemagick/convert application, I believe windows is getting confused and running the filesystem convert program.
0
 

Author Closing Comment

by:robthomas09
ID: 36569110
Thank you!
0

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.

737 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question