April 9, 2009 at 2:34 pm
I am trying execute a program that has spaces in the path like this :
EXEC xp_cmdshell '"C:\Program Files\try.exe" c:\ky\ky1.txt';
I get the following error:
" 'C:\Program' is not recognized as an internal or external command, "
I tried to add double-quotes as above but it didn't work...Can some one show me how to traverse the path ?
April 9, 2009 at 2:36 pm
You need to move the double quotes:
EXEC xp_cmdshell '"C:\Program Files\try.exe c:\ky\ky1.txt"';
April 9, 2009 at 2:39 pm
Use a single quote around the entire command and double quotes to delimit the start and end of strings.
exec master.dbo.xp_cmdshell 'dir "c:\program files\*.*" '
SQL = Scarcely Qualifies as a Language
April 9, 2009 at 4:17 pm
Thank You
April 27, 2011 at 8:10 am
I have a similar problem :
SET @command = ' "C:\Program Files (x86)\gs\gs8.64\bin>gswin32.exe" -q -sDEVICE=png16m
-dBATCH -dNOPAUSE' +' -dFirstPage=1 -dLastPage=1 -r300 -sOutputFile=' + @OutFileName
+ ' ' + @InFileName
EXEC xp_cmdshell @command
'C:\Program' is not recognized as an internal or external command
Not sure whats wrong here?
C# Gnu
____________________________________________________
April 19, 2012 at 1:35 pm
'C:\Program' is not recognized as an internal or external command
Not sure whats wrong here?
I spent some time today trying to figure this out, as I had the same issue. Basically, you need something in front of your qualified path in xp_cmdshell.
I was trying to qualify the version of dtexec.exe I was using (as I have both 2005 and 2008 on this server, leading to the wrong dtexec being picked up from the path environment variable). I changed my command to include a cd.. in front of the command.
Old:
exec xp_cmdshell '"D:\Program Files\Microsoft SQL Server\SQL 2005\100\DTS\Binn\dtexec.exe" ..... '
This threw the same error you are getting.
New:
exec xp_cmdshell 'cd.. && "D:\Program Files\Microsoft SQL Server\SQL 2005\100\DTS\Binn\dtexec.exe" ..... '
This did it. Just make sure your qualified path is not the first item in the command, and it works. Kinda stupid!
April 26, 2012 at 1:47 am
Hello,
I had to have a look back and see how I sorted this out .. and here was my solution:-
Basically I write the command line into a batch file, then exec the batch file, capturing any error.
-- Create the command
SET @command = 'echo "C:\Program Files (x86)\gs\gs8.64\bin\gswin32.exe" -q -sDEVICE=png16m -dBATCH -dNOPAUSE'
+ ' -r300 -dNOPROMPT -sOutputFile='
+ '"' + @OutFileName + '" "' + @InFileName + '" > ' + @cmdFileName
SELECT @command
-- Insert command into a batch/command file
INSERT #result
EXEC @ReturnCode = master.dbo.xp_cmdshell @command
SET @ShellErrorMessage = ''
SELECT @ShellErrorMessage = @ShellErrorMessage + SomeCol
FROM #result
WHERE SomeCol IS NOT NULL
IF @ReturnCode <> 0
RAISERROR (@ShellErrorMessage,16,1)
DELETE #result
-- Exec the batch file
SET @command = @cmdFileName
INSERT #result
EXEC @ReturnCode = master.dbo.xp_cmdshell @command
SET @ShellErrorMessage = ''
SELECT @ShellErrorMessage = @ShellErrorMessage + SomeCol
FROM #result
WHERE SomeCol IS NOT NULL
IF @ReturnCode <> 0
RAISERROR (@ShellErrorMessage,16,1)
DELETE #result
C# Gnu
____________________________________________________
February 5, 2015 at 1:04 pm
Worked for me. Thanks
December 14, 2021 at 10:01 pm
You can do something like this too....
DECLARE @p_cmd varchar(255)
SET @p_cmd = 'cd "C:\Program Files\edb\mtk\bin" && runMTK.bat -dataOnly -tables table_changes -sourcedbtype sqlserver -targetdbtype postgresql -targetSchema public dbo'
EXEC xp_cmdshell @p_cmd?
Viewing 9 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy