Solved

SQL xp_cmdshell errors. MSSQL, Programming, ImageMagick

Posted on 2011-09-12
8
430 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
  • 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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

830 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