Solved

execute operating system command in sql job

Posted on 2014-04-10
7
273 Views
Last Modified: 2014-04-30
Hello,

I try to execute this command in sql agent :
DECLARE @command varchar(8000)
SET @command = '"C:\Microsoft SQL Server Migration Assistant for Oracle\bin\"SSMAforOracleConsole.exe -s E:\ConversionAndDataMigration.xml -v E:\LV\VariableValueFile.xml'
EXEC master..xp_cmdshell @command

The following error is returned :
output
'C:\Microsoft' is not recognized as an internal or external command,

Why?

Thanks
0
Comment
Question by:bibi92
  • 3
7 Comments
 
LVL 20

Accepted Solution

by:
netcmh earned 300 total points
ID: 39992715
Change your strings to
'"C:\Microsoft SQL Server Migration Assistant for Oracle\bin\SSMAforOracleConsole.exe"
and
"E:\ConversionAndDataMigration.xml"
and
"E:\LV\VariableValueFile.xml"'

So, single quotes to contain everything with the double quotes to complete the paths.
0
 
LVL 20

Expert Comment

by:netcmh
ID: 39992716
Our IPS is catching the entirety of the command as a malicious attempt. Sorry :)
0
 
LVL 26

Assisted Solution

by:Zberteoc
Zberteoc earned 200 total points
ID: 39992884
Use this:
DECLARE 
	@command varchar(8000)
-- create a temp table to grab the output
create table #cmmmand_output
	(	id int identity, 
		line varchar(8000))
-- build the command
SET 
	@command = '"C:\Microsoft SQL Server Migration Assistant for Oracle\bin\SSMAforOracleConsole.exe" -s "E:\ConversionAndDataMigration.xml" -v "E:\LV\VariableValueFile.xml"' 
--execute the command and grab the output lines
insert into #cmmmand_output(line)
EXEC master..xp_cmdshell @command

-- get the output result
select 
	line 
from 
	#cmmmand_output 
where 
	line is not null 
order by id

Open in new window

I also added a temp table to grab the command execution output. It is useful if you want to check for particular result, like if successful or not.
0
 
LVL 20

Expert Comment

by:netcmh
ID: 40031750
Thank you.
0

Featured Post

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

705 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

20 Experts available now in Live!

Get 1:1 Help Now