Solved

SQL xp_cmdshell errors. MSSQL, Programming, ImageMagick

Posted on 2011-09-12
8
414 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 M
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
 
LVL 25

Expert Comment

by:Ron M
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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 25

Expert Comment

by:Ron M
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 M 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

758 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now