Solved

execute operating system command in sql job

Posted on 2014-04-10
7
282 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
T-SQL 10 35
SQL Stored Proc - Performance Enhancement 15 58
AD and SQL Server 2016 2 30
SQL Server show list of tables from a database with a parameter for the Database name 18 20
Having an SQL database can be a big investment for a small company. Hardware, setup and of course, the price of software all add up to a big bill that some companies may not be able to absorb.  Luckily, there is a free version SQL Express, but does …
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 SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

821 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