How to access c:\Program files\..... in master..xp_cmdshell in T-sql

  • Hi

    I was trying to run the below query

    exec master..xp_cmdshell 'C:\Program Files\7-Zip\7z.exe a "D:ew.7z" "c:ew\"'

    But it was giving the output as 'c:\program' is not a internal or external command

    Can anybody help me on the same.

    Regards,

    Vaithilingam.k

  • How about:

    exec master..xp_cmdshell '"C:\Program Files\7-Zip\7z.exe" a "D:ew.7z" "c:ew\"'

    CEWII

  • The space is the problem. Another option is to use the 8.3 path name:

    C:\PROGRA~1\...

  • Hi Elliott Whitlow,

    It is not executing to me. is it executing to you?

  • here's what i use, just retested the syntax:

    --http://www.7-zip.org/download.html

    --http://downloads.sourceforge.net/sevenzip/7za920.zip

    DECLARE @results TABLE(results varchar(255))

    declare @command varchar(2000)

    --zip one file

    SET @command =

    '"C:\DataFiles\7zip_CommandLine_7za465\' --path to 7za command line utility note the dbl quotes for long file names!

    + '7za.exe"' --the exe: i'm using in the command line utility.

    + ' a ' --the Add command: add to zip file:

    + 'C:\DataFiles\' --path for zip

    + 'myZipFile.zip' --zip file name, note the dbl quotes for long file names!

    + ' ' --whitespace between zip file and file to add

    + 'C:\Data\' --path for the files to add

    + 'Mybackup.bak' --the file

    + ' -y' --suppress any dialogs by answering yes to any and all prompts

    print @command

    --"C:\DataFiles\7zip_CommandLine_7za465\7za.exe" a "C:\DataFiles\myZipFile.zip" "C:\DataFiles\SandBox_2011-07-25.bak" -y

    insert into @results

    exec xp_cmdshell @command

    select * from @results

    results:

    /*

    NULL

    7-Zip (A) 4.65 Copyright (c) 1999-2009 Igor Pavlov 2009-02-03

    Scanning

    NULL

    Creating archive C:\DataFiles\myZipFile.zip

    NULL

    Compressing Mybackup.bak

    NULL

    Everything is Ok

    NULL

    */

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • vaithi.saran846 (9/27/2011)


    Hi Elliott Whitlow,

    It is not executing to me. is it executing to you?

    Hm, interesting..

    try this:

    exec master..xp_cmdshell 'C:\"Program Files"\7-Zip\7z.exe a "D:ew.7z" "c:ew\"'

    It appears to work.. don't like it, but it does work. Now whether it does what you want is for you to decide, but getting 7zip to run isn't the problem..

    Found the resolution about 1/3 of the way down here:

    http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=34121

    CEWII

  • Hello,

    I run this. But it show me 'C:\"Program Files"\7-Zip\7za.exe' is not recognized as an internal or external command,

    It this "Program Files" problem. Space?

    Please let me know.

  • I try this. But it seems on running forever. Do anyone know why?

  • Put the whole path to the executable in double quotes. If you have a 32-bit parameter, put it in double quotes as well.

    You also need to have the program installed on the server, not on your desktop. Remember, the query is executed on the server. Make sure your path is correct and that the SQL Server service account has permission to run the command, including whatever network resources you use in the command.

    Once you get the command working in a command prompt window and security is good, you should be able to run the command from SQL Server.

Viewing 9 posts - 1 through 8 (of 8 total)

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