Solved

execute operating system command in sql job

Posted on 2014-04-10
7
289 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
[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
  • 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 27

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

628 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