Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL xp_cmdshell errors. MSSQL, Programming, ImageMagick

Posted on 2011-09-12
8
Medium Priority
?
456 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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 2000 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

Make the most of your online learning experience.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
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…
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…

604 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