Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Prob Running Batch file from xp_cmdshell

Status
Not open for further replies.

SSesham

Programmer
Feb 26, 2004
17
US
declare @client varchar(25), @outputfilename varchar(30)

SET @client = 'MYCLIENT'
SET @outputfilename = @client + '.txt'

declare @cmd varchar(255)

set @cmd = 'C:\Database\Disease_Registry\Common\ReleaseP4PandDR\TrimSpaces.bat ' + @outputfilename

exec master..xp_cmdshell @cmd

This code is returning "The system cannot find the specified path"..BUT when i extract the @cmd variable and run it from command prompt it works fine. is there a special way of running a batch file from the Xp_cmdshell?
thank you very much for your time in advance.
 
Does your output file have spaces in it? Try putting double quotes around it in your script.
 
Are you sure that the listed file exists on the SQL Server? Does it work when you run it from the command line on the SQL Server or your workstation?

Denny
MCSA (2003) / MCDBA (SQL 2000) / MCTS (SQL 2005) / MCITP Database Administrator (SQL 2005)

--Anything is possible. All it takes is a little research. (Me)
[noevil]
 
sorry, placing double quotes does not do anything.

the text file has spaces and i'm trucating it with a cscript and vbs file..which i placed in a batch file.no i need to run the batch file with a parameter from xp_cmdshell .

the command i'm running to get this output text file is

C:\Database\Disease_Registry\Common\ReleaseP4PandDR>osql -E -S server5 -d myDB -s "," -h-1 -n -w 100 -i input.sql -o output.txt


 
Yes! it runs fine when i run the value in @cmd from the command window. its confusing why it wont work from a xp_cmdshell when the string is correct!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top