Xp_cmdshell path question

  • Hello,

    Speaking of Xp_cmdshell.

    The below command works fine:

    declare @command varchar(1000)

    SET @command='master..xp_cmdshell "E:\NewFolder\CreateDateFolder.exe"'

    EXECUTE (@command)

    However, when 'NewFolder' is being changed to 'New Folder' (with a space between 2 words)

    I am getting an error.

    Any ideas?

    Also, can Xp_cmdshell pass parameters? And if yes, can you provide an example.

    Thanks.

    ad

  • If you set it this way it will work.

    declare @command varchar(1000), @folder varchar(20), @STR varchar(100)

    SET @folder = 'New Folder'

    SET @STR = ' del "s:\sysadmin\'+ @folder + '\test.txt"'

    SET @command = 'master..xp_cmdshell ' + char(39) + @STR + char(39)

    select @command

    exec (@command)

    mom

  • Hi, I have created this procedure:

    CREATE PROCEDURE ExecInsertCmd

    -- Add the parameters for the stored procedure here

    @Table varchar(255),

    @InputFilePath varchar(5000)

    AS

    BEGIN

    -- SET NOCOUNT ON added to prevent extra result sets from

    -- interfering with SELECT statements.

    SET NOCOUNT ON;

    /*DECLARE @Table varchar(255)

    DECLARE @InputFilePath varchar(5000)

    SET @Table = 'tbl_tareatipo'

    SET @InputFilePath = 'C:\Temp\PlutonDevScripts\Maestros\'

    */

    -- Insert statements for procedure here

    DECLARE @SQLCMDPath varchar(500)

    DECLARE @SQLCMDInput varchar(500)

    DECLARE @SQLCMDOutput varchar(500)

    DECLARE @SQLCMD varchar(1500)

    SET @SQLCMDPath = '"C:\Program Files\Microsoft SQL Server\90\Tools\Binn\sqlcmd.exe" -S gerencia -d Plutondev -E '

    SET @SQLCMDInput = @InputFilePath + @Table +'.sql'

    SET @SQLCMDOutput = @InputFilePath + @Table +'.out'

    SET @SQLCMD = @SQLCMDPath + ' -i' + @SQLCMDInput + ' -o' + @SQLCMDOutput

    EXEC('SET IDENTITY_INSERT ' + @Table + ' ON')

    EXEC master..xp_cmdshell @SQLCMD

    EXEC('SET IDENTITY_INSERT ' + @Table + ' OFF')

    END

    GO

    Executed by this line: EXEC ExecInsertCmd 'tbl_tareatipo', 'C:\Temp\PlutonDevScripts\02Maestros\'

    but havent been able to make it work.

    The idea is that I am traying to run some insert scripts that requires the indentity insert set to on.

    The errors that it gives me are:

    'C:\Program' is not recognized as an internal or external command,operable program or batch file.'

    And when I review the output of the generated file (.out):

    Msg 544, Level 16, State 1, Server GERENCIA, Line 1

    Cannot insert explicit value for identity column in table 'tbl_tareatipo' when IDENTITY_INSERT is set to OFF.

    Any help would be appreciated.

    Rgds

    Ricardo

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply