Zipping a txt file

Former Member
Former Member $organization

Hi

I'm trying to zip a Text file in SQL but once I run the command, sql keeps executing for long time and I don't get any error.

EXEC master..xp_cmdshell 'T:\Source\WinZip\winzip32.exe T:\Source\sso_pacingdata.zip T:\Source\sso_pacingdata.txt'

I also tried,

EXEC master..xp_cmdshell 'T:\source\WinZip\winzip32.exe -o T:\Source\sso_pacingdata.txt'

Probably my syntax is wrong. Can anyone please let me know the right syntax to Zip a Text file.

Thanks

Varsha

  • Former Member
    Former Member $organization

    No Ben, I can run the Batch file from Windows Command prompt. I also tried scheduling Windows Task Scheduler and it successfully created the ZIP file but when I run that same batch file in SQL ;

     

    Execute master..xp_cmdshell ‘\\dell\tessitura\source\text_zip_cmd.bat’

     

    Then it doesn’t work.

     

    Xp_cmdshell works fine because I did

     

    Master..xp_cmdshell ‘dir \\dell\tessitura\source’ etc to see which files are accessible from SQL Server.

     

    This 7zip, I’ve installed but now I’m again getting ‘The system can not find path specified’

     

    execute master..xp_cmdshell '"\\Dell\Tessitura\Source\7-Zip\7za.exe" a "\\Dell\Tessitura\Source\sso_pacingdata.zip" "\\Dell\Tessitura\Source\sso_pacingdata.txt" -y'

     

    I’m getting quite frustrated… But at least windows task scheduler is helping me here…

     

    Varsha

     

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Ben Gu
    Sent: Monday, 6 December 2010 4:37 PM
    To: Varsha Karnik
    Subject: RE: [Tessitura Technical Forum] Zipping a txt file

     

    HI Normal 0 false false false EN-AU ZH-CN X-NONE MicrosoftInternetExplorer4 Varsha,

    do you mean you can run cmd in sql server machine but you fail to run it master..xpcmdshell?

    7-zip has very similar syntax.

    if you install 7-zip in the same location, the syntax difference will be change from "-a" to "a" ( remove the "-").

     

    Ben

    From: Varsha Karnik <bounce-varshakarnik2805@tessituranetwork.com>
    Sent: 12/5/2010 10:28:15 PM

    WINZIP is actually installed on my computer and SQL server also the add-on, but still doesn’t work. I think I will try 7-zip. Does 7-zip have same syntax?

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Ben Gu
    Sent: Monday, 6 December 2010 3:12 PM
    To: Varsha Karnik
    Subject: RE: [Tessitura Technical Forum] Zipping a txt file

     

    Hi Varsha,

    Good day.

    the machine runs master..xp_cmdshell 'Text_Zip_Cmd.Bat' need a copy of winzip.

    So, I think you need to install winzip on the sql server if you want to schedule this as a sql job.

    (I think you can use 7-zip, it is free.)

     

     

    have fun

    Ben

     

     

    From: Varsha Karnik <bounce-varshakarnik2805@tessituranetwork.com>
    Sent: 12/5/2010 6:43:15 PM

    I've create batch file:

     

    @Echo off

     

    "\\keenm\c$\WinZip\WZZIP.exe" "\\Dell\Tessitura\Source\sso_pacingdata.zip" "\\Dell\Tessitura\Source\sso_pacingdata.txt"

    ---------------

    Now I run

     

    master..xp_cmdshell 'Text_Zip_Cmd.Bat'

     

    It runs perfectly from command prompt but in SQL i get following error.

     

    ERROR(\\keenm\c$\WinZip\WZZIP.EXE,103): WinZip is not installed.

    You must install WinZip in order to use the WinZip Command Line Support Add-On

    NULL

     

    Earlier I thought it was Winzip license issue but after fixing it and also installing command line add-on I'm getting this error.

     

    When I run xp_cmdshell 'dir \\keenm\c$\winzip' I can see all files..

     

    similarly when I run xp_cmdshell 'dir \\dell\tessitura\source' I can see all files..

     

    that means I'm able to access all files, but I can't understand what’s missing when it comes to SQL Server.

     

    Any help will be appreciated..

     

    Thanks

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Ben Gu
    Sent: Thursday, 2 December 2010 12:56 PM
    To: Varsha Karnik
    Subject: RE: [Tessitura Technical Forum] Zipping a txt file

     

    Hi Varsha,

    good day.

    the easiest way to fix the permission issue is using  'Execute as'.

    in the stored procedure, you can do something like this:

     

    ALTER      PROCEDURE [dbo].[AP_BCP_FILE]
        (
         @file_name     varchar(255),
         @format_file     varchar(255),
         @table_name     varchar(255),
         @db_login     varchar(255),
         @db_password     varchar(255) = NULL,
         @bcp_in_out    varchar(10),
         @err_file    varchar(255) = null,
         @hint        varchar(255) = NULL,
         @cDebug    char(1) = 'N',
         @include_output char(1) = 'Y'        -- added 3/12/2007 by lwl
        )
    WITH EXECUTE AS 'dbo' -----you can replace dbo to 'mynetwork\admin'
    AS

    you can put network admin account in sql account, then you can use that account do some special things when you need access network resource.

     

     

    have fun

    Ben

    From: Varsha Karnik <bounce-varshakarnik2805@tessituranetwork.com>
    Sent: 12/1/2010 7:27:33 PM

    Ben

     

    The total length with full path of @cmd is 129 characters so there I’m safe.

     

    After fixing WINZIP license issue, .Bat files works perfectly on command prompt - \\Dell\Tessitura\Source\Text_Zip_Cmd.Bat

     

    but when I run it in SQL it says “System Can not find the Path specified”

     

    EXEC master..XP_CmdShell '\\Dell\Tessitura\Source\Text_Zip_Cmd.Bat'

     

    In SQL forum I found out that maybe my SQL Server doesn’t have access to C: but I am not sure how to make C Drive accessible to SQL? Zip file is sitting in C:Program Files\Winzip.

     

    Any advise on this?

     

    Thanks

    Varsha

     

     

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Ben Gu
    Sent: Wednesday, 1 December 2010 4:48 PM
    To: Varsha Karnik
    Subject: RE: [Tessitura Technical Forum] Zipping a txt file

     

    Hi Varsha,

    good day.

    I think the error message maybe have something to do with "Total path and file name length must not exceed 260 characters"

     

    http://www.question-defense.com/2010/10/25/winrar-extract-error-total-path-and-file-name-length-must-not-exceed-260-characters

    the link is about winrar error message.

    how about you map " Normal 0 false false false EN-AU X-NONE X-NONE MicrosoftInternetExplorer4 \\Dell\Tessitura\Source Normal 0 false false false EN-AU X-NONE X-NONE MicrosoftInternetExplorer4 \" to z: drive, create a "a.txt' file.

    and test this:

    declare @cmd varchar(1000)

    set @cmd='"Z:\WinZip\winzip32.exe" -a "Z:\a.zip" "z\a.txt"'
    select @cmd
    EXEC master..xp_cmdshell @cmd

     

     

    have fun

    Ben

     

     

    From: Varsha Karnik <bounce-varshakarnik2805@tessituranetwork.com>
    Sent: 11/30/2010 8:42:32 PM

    Now I get error that “System cannot find the path specified.”

     

    declare @cmd varchar(1000)

     

    set @cmd='"\\Dell\Tessitura\Source\WinZip\winzip32.exe" -a "\\Dell\Tessitura\Source\sso_pacingdata.zip" "\\Dell\Tessitura\Source\sso_pacingdata.txt"'

    select @cmd

    EXEC master..xp_cmdshell @cmd

     

     

    I changed T: drive to full path as I thought it may not recognise drive but still doesn’t work.

     

    Is it permission issue for xp_cmdshell? If so what should I check?

     

    Thanks

    Varsha

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Ben Gu
    Sent: Wednesday, 1 December 2010 1:18 PM
    To: Varsha Karnik
    Subject: RE: [Tessitura Technical Forum] Zipping a txt file

     

    Hi Varsha,

     

    I agree with Ken, you can test it in cmd windows, and I think you should use option -a not -o too.

    this will work.

    declare @cmd varchar(1000)

    set @cmd='"T:\Source\WinZip\winzip32.exe" -a "T:\Source\sso_pacingdata.zip" "T:\Source\sso_pacingdata.txt"'
    select @cmd
    EXEC master..xp_cmdshell @cmd

     

    have fun

    Ben

     

    From: Ken McSwain <bounce-kenmcswain5454@tessituranetwork.com>
    Sent: 11/30/2010 7:42:32 PM

    But the first  question is – Does this command-line work if you run it from a batch file?

    If it doesn’t, then it’s not a SQL syntax problem, it’s a Winzip syntax problem.

     

    ...and I have a feeling –o is an extraction option code, rather than a compression option code. I’d try –a ( add) as the option code instead.

     

    Ken McSwain Business solutions Manager

    kmcswain@sydneyoperahouse.com

    T+61 2 9250 7876  F+61 2 9251 7821  M 0418 659 360

     

    SYDNEY OPERA HOUSE BENNELONG POINT

    GPO BOX 4274, SYDNEY NSW 2001, AUSTRALIA

    SYDNEYOPERAHOUSE.COM

     

     

    Please consider the environment before printing this email.
        =====This message is intended for the addressee(s) named and may contain confidential information.
        If you are not the intended recipient, please delete it and notify the sender.
        Views expressed in this email are those of the individual sender and are not necessarily the views of the Sydney Opera House Trust=====




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!

  • HI Varsha,

    Good day.

    I think if you run cmd and windows task scheduler. it is running something from your local machine.

    If you run something from master..xp_cmdshell, it is running from SQL server machine.

    if you have sql instance install on your local machine, you login into the local instance and run master..xp_cmdshell from there.

     

    It means if run xp_cmdshell, it starts from C:\windows\system32 on the instance of the sql server.

    so the path will be different.

    if you install winzip on sql server, in the bat file

    it should be

    -----------------------

    cd\

    "c:\program files\winzip\winzip.exe" -a "\\dell\source\a.zip" "\\dell\source\a.txt"

     

    ----------------------------

     

    have fun

     

    Ben

     

     

     



    [edited by: Ben Gu at 1:07 AM (GMT -6) on 6 Dec 2010]
  • Former Member
    Former Member $organization

    Finally after so many days of R&D, i've scheduled the zipping task on Windows Task Scheduler and its solved my problem. I definitely wanted to use master..xp_cmdshell on SQL Server but looks like it will not be possible. Its privileges problem indeed. I will keep trying but for time being it’s all sorted.

    Thanks a lot for helping.

    regards
    Varsha

     

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Ben Gu
    Sent: Monday, 6 December 2010 6:07 PM
    To: Varsha Karnik
    Subject: RE: [Tessitura Technical Forum] Zipping a txt file

     

    HI Varsha,

    Good day.

    I think if you run cmd and windows task scheduler. it is running something from your local machine.

    If you run something from master..xp_cmdshell, it is running from SQL server machine.

    if you have sql instance install on your local machine, you login into the local instance and run master..xp_cmdshell from there.

     

    It means if run xp_cmdshell, it starts from C:\windows\system32 on the instance of the sql server.

    so the path will different.

    if you install winzip on sql server, in the bat file

    it should be

    -----------------------

    cd\

    "c:\program files\winzip\winzip.exe" -a "\\dell\source\a.zip" "\\dell\source\a.txt"

     

    ----------------------------

     

    have fun

     

    Ben

     

     

     

    From: Varsha Karnik <bounce-varshakarnik2805@tessituranetwork.com>
    Sent: 12/5/2010 11:53:16 PM

    No Ben, I can run the Batch file from Windows Command prompt. I also tried scheduling Windows Task Scheduler and it successfully created the ZIP file but when I run that same batch file in SQL ;

     

    Execute master..xp_cmdshell ‘\\dell\tessitura\source\text_zip_cmd.bat’

     

    Then it doesn’t work.

     

    Xp_cmdshell works fine because I did

     

    Master..xp_cmdshell ‘dir \\dell\tessitura\source’ etc to see which files are accessible from SQL Server.

     

    This 7zip, I’ve installed but now I’m again getting ‘The system can not find path specified’

     

    execute master..xp_cmdshell '"\\Dell\Tessitura\Source\7-Zip\7za.exe" a "\\Dell\Tessitura\Source\sso_pacingdata.zip" "\\Dell\Tessitura\Source\sso_pacingdata.txt" -y'

     

    I’m getting quite frustrated… But at least windows task scheduler is helping me here…

     

    Varsha

     

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Ben Gu
    Sent: Monday, 6 December 2010 4:37 PM
    To: Varsha Karnik
    Subject: RE: [Tessitura Technical Forum] Zipping a txt file

     

    HI Normal 0 false false false EN-AU ZH-CN X-NONE MicrosoftInternetExplorer4 Varsha,

    do you mean you can run cmd in sql server machine but you fail to run it master..xpcmdshell?

    7-zip has very similar syntax.

    if you install 7-zip in the same location, the syntax difference will be change from "-a" to "a" ( remove the "-").

     

    Ben

    From: Varsha Karnik <bounce-varshakarnik2805@tessituranetwork.com>
    Sent: 12/5/2010 10:28:15 PM

    WINZIP is actually installed on my computer and SQL server also the add-on, but still doesn’t work. I think I will try 7-zip. Does 7-zip have same syntax?

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Ben Gu
    Sent: Monday, 6 December 2010 3:12 PM
    To: Varsha Karnik
    Subject: RE: [Tessitura Technical Forum] Zipping a txt file

     

    Hi Varsha,

    Good day.

    the machine runs master..xp_cmdshell 'Text_Zip_Cmd.Bat' need a copy of winzip.

    So, I think you need to install winzip on the sql server if you want to schedule this as a sql job.

    (I think you can use 7-zip, it is free.)

     

     

    have fun

    Ben

     

     

    From: Varsha Karnik <bounce-varshakarnik2805@tessituranetwork.com>
    Sent: 12/5/2010 6:43:15 PM

    I've create batch file:

     

    @Echo off

     

    "\\keenm\c$\WinZip\WZZIP.exe" "\\Dell\Tessitura\Source\sso_pacingdata.zip" "\\Dell\Tessitura\Source\sso_pacingdata.txt"

    ---------------

    Now I run

     

    master..xp_cmdshell 'Text_Zip_Cmd.Bat'

     

    It runs perfectly from command prompt but in SQL i get following error.

     

    ERROR(\\keenm\c$\WinZip\WZZIP.EXE,103): WinZip is not installed.

    You must install WinZip in order to use the WinZip Command Line Support Add-On

    NULL

     

    Earlier I thought it was Winzip license issue but after fixing it and also installing command line add-on I'm getting this error.

     

    When I run xp_cmdshell 'dir \\keenm\c$\winzip' I can see all files..

     

    similarly when I run xp_cmdshell 'dir \\dell\tessitura\source' I can see all files..

     

    that means I'm able to access all files, but I can't understand what’s missing when it comes to SQL Server.

     

    Any help will be appreciated..

     

    Thanks

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Ben Gu
    Sent: Thursday, 2 December 2010 12:56 PM
    To: Varsha Karnik
    Subject: RE: [Tessitura Technical Forum] Zipping a txt file

     

    Hi Varsha,

    good day.

    the easiest way to fix the permission issue is using  'Execute as'.

    in the stored procedure, you can do something like this:

     

    ALTER      PROCEDURE [dbo].[AP_BCP_FILE]
        (
         @file_name     varchar(255),
         @format_file     varchar(255),
         @table_name     varchar(255),
         @db_login     varchar(255),
         @db_password     varchar(255) = NULL,
         @bcp_in_out    varchar(10),
         @err_file    varchar(255) = null,
         @hint        varchar(255) = NULL,
         @cDebug    char(1) = 'N',
         @include_output char(1) = 'Y'        -- added 3/12/2007 by lwl
        )
    WITH EXECUTE AS 'dbo' -----you can replace dbo to 'mynetwork\admin'
    AS

    you can put network admin account in sql account, then you can use that account do some special things when you need access network resource.

     

     

    have fun

    Ben

    From: Varsha Karnik <bounce-varshakarnik2805@tessituranetwork.com>
    Sent: 12/1/2010 7:27:33 PM

    Ben

     

    The total length with full path of @cmd is 129 characters so there I’m safe.

     

    After fixing WINZIP license issue, .Bat files works perfectly on command prompt - \\Dell\Tessitura\Source\Text_Zip_Cmd.Bat

     

    but when I run it in SQL it says “System Can not find the Path specified”

     

    EXEC master..XP_CmdShell '\\Dell\Tessitura\Source\Text_Zip_Cmd.Bat'

     

    In SQL forum I found out that maybe my SQL Server doesn’t have access to C: but I am not sure how to make C Drive accessible to SQL? Zip file is sitting in C:Program Files\Winzip.

     

    Any advise on this?

     

    Thanks

    Varsha

     

     

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Ben Gu
    Sent: Wednesday, 1 December 2010 4:48 PM
    To: Varsha Karnik
    Subject: RE: [Tessitura Technical Forum] Zipping a txt file

     

    Hi Varsha,

    good day.

    I think the error message maybe have something to do with "Total path and file name length must not exceed 260 characters"

     

    http://www.question-defense.com/2010/10/25/winrar-extract-error-total-path-and-file-name-length-must-not-exceed-260-characters

    the link is about winrar error message.

    how about you map " Normal 0 false false false EN-AU X-NONE X-NONE MicrosoftInternetExplorer4 \\Dell\Tessitura\Source Normal 0 false false false EN-AU X-NONE X-NONE MicrosoftInternetExplorer4 \" to z: drive, create a "a.txt' file.

    and test this:

    declare @cmd varchar(1000)

    set @cmd='"Z:\WinZip\winzip32.exe" -a "Z:\a.zip" "z\a.txt"'
    select @cmd
    EXEC master..xp_cmdshell @cmd

     

     

    have fun

    Ben

     

     

    From: Varsha Karnik <bounce-varshakarnik2805@tessituranetwork.com>
    Sent: 11/30/2010 8:42:32 PM

    Now I get error that “System cannot find the path specified.”

     

    declare @cmd varchar(1000)

     

    set @cmd='"\\Dell\Tessitura\Source\WinZip\winzip32.exe" -a "\\Dell\Tessitura\Source\sso_pacingdata.zip" "\\Dell\Tessitura\Source\sso_pacingdata.txt"'

    select @cmd

    EXEC master..xp_cmdshell @cmd

     

     

    I changed T: drive to full path as I thought it may not recognise drive but still doesn’t work.

     

    Is it permission issue for xp_cmdshell? If so what should I check?

     

    Thanks

    Varsha

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Ben Gu
    Sent: Wednesday, 1 December 2010 1:18 PM
    To: Varsha Karnik
    Subject: RE: [Tessitura Technical Forum] Zipping a txt file

     

    Hi Varsha,

     

    I agree with Ken, you can test it in cmd windows, and I think you should use option -a not -o too.

    this will work.

    declare @cmd varchar(1000)

    set @cmd='"T:\Source\WinZip\winzip32.exe" -a "T:\Source\sso_pacingdata.zip" "T:\Source\sso_pacingdata.txt"'
    select @cmd
    EXEC master..xp_cmdshell @cmd

     

    have fun

    Ben

     

    From: Ken McSwain <bounce-kenmcswain5454@tessituranetwork.com>
    Sent: 11/30/2010 7:42:32 PM

    But the first  question is – Does this command-line work if you run it from a batch file?

    If it doesn’t, then it’s not a SQL syntax problem, it’s a Winzip syntax problem.

     

    ...and I have a feeling –o is an extraction option code, rather than a compression option code. I’d try –a ( add) as the option code instead.

     

    Ken McSwain Business solutions Manager

    kmcswain@sydneyoperahouse.com

    T+61 2 9250 7876  F+61 2 9251 7821  M 0418 659 360

     

    SYDNEY OPERA HOUSE BENNELONG POINT

    GPO BOX 4274, SYDNEY NSW 2001, AUSTRALIA

    SYDNEYOPERAHOUSE.COM

     

     

    Please consider the environment before printing this email.
         =====This message is intended for the addressee(s) named and may contain confidential information.
         If you are not the intended recipient, please delete it and notify the sender.
         Views expressed in this email are those of the individual sender and are not necessarily the views of the Sydney Opera House Trust=====




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!

  • Hi Varsha,

    Good day.

    here is a way to use xp_cmdshell.

     


    steps to run xp_cmdshell.

    step1,


    stored procedure:

    create procedure lp_7zip
    WITH EXECUTE AS 'mynetwork\NetWorkAmdin'

    as
    begin

    exec master..xp_cmdshell 'c:\a\a.bat'  ---it is in sql server c: drive

    end


    step2


    in a.bat file


    --------------------------
    cd\
    "c:\winzip\7z.exe" a "\\mtc.com.au\mtc\Finance\Ben Gu\a\a.zip" "\\mtc.com.au\mtc\Finance\Ben Gu\a\a.txt"
    ------------------------------

    step3


    Credential account

    Credential name:
    ##xp_cmdshell_proxy_account##

    Identity:
    mynetwork\NetWorkAmdin
    passowrd:
    **********
    Comfirm passowrd:
    *********

     

    have fun

     

    Ben

  • $organization in reply to Ben Gu

    Hi Varsha,

    I found a very interesting thing in  the xp_cmshell.

    this one work:

    exec master..xp_cmdshell 'c:\winzip\7z.exe a "c:\a\a.zip" "c:\a\a.txt"'

    this one doesn't:

    exec master..xp_cmdshell '"c:\winzip\7z.exe" a "c:\a\a.zip" "c:\a\a.txt"'

    ---

    but

    c:\winzip\7z.exe a "c:\a\a.zip" "c:\a\a.txt"

    and

    "c:\winzip\7z.exe" a "c:\a\a.zip" "c:\a\a.txt"

    both  work in cmd.

    have fun

    Ben

  • Former Member
    Former Member $organization

    Ben

     

    I can’t believe this,

     

    As per your script, I wrote thio=s code and it actually worked…

     

    exec master..xp_cmdshell '\\dell\tessitura\source\7-zip\7zG.exe a "\\dell\tessitura\source\sso_pacingdata.zip" "\\dell\tessitura\source\sso_pacingdataxt"'

     

    but the SQL is not stopping. The Zip is ready but I haven’t got any return outut in SQL. It’s still executing…

     

    what could be the problem? Does it need an output file?

     

    Thanks a lot…

     

    Varsha

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Ben Gu
    Sent: Tuesday, 7 December 2010 2:07 PM
    To: Varsha Karnik
    Subject: RE: [Tessitura Technical Forum] Zipping a txt file

     

    Hi Varsha,

    I found a very interesting thing in  the xp_cmshell.

    this one work:

    exec master..xp_cmdshell 'c:\winzip\7z.exe a "c:\a\a.zip" "c:\a\a.txt"'

    this one doesn't:

    exec master..xp_cmdshell '"c:\winzip\7z.exe" a "c:\a\a.zip" "c:\a\a.txt"'

    ---

    but

    c:\winzip\7z.exe a "c:\a\a.zip" "c:\a\a.txt"

    and

    "c:\winzip\7z.exe" a "c:\a\a.zip" "c:\a\a.txt"

    both  work in cmd.

    have fun

    Ben

    From: Ben Gu <bounce-bengu4278@tessituranetwork.com>
    Sent: 12/6/2010 8:42:37 PM

    Hi Varsha,

    Good day.

    here is a way to use xp_cmdshell.

     


    steps to run xp_cmdshell.

    step1,


    stored procedure:

    create procedure lp_7zip
    WITH EXECUTE AS 'mynetwork\NetWorkAmdin'

    as
    begin

    exec master..xp_cmdshell 'c:\a\a.bat'  ---it is in sql server c: drive

    end


    step2


    in a.bat file


    --------------------------
    cd\
    "c:\winzip\7z.exe" a "\\mtc.com.au\mtc\Finance\Ben Gu\a\a.zip" "\\mtc.com.au\mtc\Finance\Ben Gu\a\a.txt"
    ------------------------------

    step3


    Credential account

    Credential name:
    ##xp_cmdshell_proxy_account##

    Identity:
    mynetwork\NetWorkAmdin
    passowrd:
    **********
    Comfirm passowrd:
    *********

     

    have fun

     

    Ben




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!

  • Hi Varsha,

    you can use no_output keyword if you want to.

    xp_cmdshell (Transact-SQL)

    http://msdn.microsoft.com/en-us/library/ms175046%28v=SQL.90%29.aspx

    EXEC xp_cmdshell 'blabalbla', no_output


    if you think there is a problem.
    you can check SQL logs or check Activity Monitor under Management.

    have fun

    Ben
  • Former Member
    Former Member $organization

    Ben

     

    It worked, thanks a lot… I used –y switch to answer all Q Yes…

     

    exec master..xp_cmdshell '\\dell\tessitura\source\7-zip\7zG.exe a "\\dell\tessitura\source\sso_pacingdata.zip" "\\dell\tessitura\source\sso_pacingdata.txt" -y'

     

    Thanks a million…

     

    Varsha

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Varsha Karnik
    Sent: Tuesday, 7 December 2010 2:22 PM
    To: Varsha Karnik
    Subject: RE: [Tessitura Technical Forum] Zipping a txt file

     

    Ben

     

    I can’t believe this,

     

    As per your script, I wrote thio=s code and it actually worked…

     

    exec master..xp_cmdshell '\\dell\tessitura\source\7-zip\7zG.exe a "\\dell\tessitura\source\sso_pacingdata.zip" "\\dell\tessitura\source\sso_pacingdataxt"'

     

    but the SQL is not stopping. The Zip is ready but I haven’t got any return outut in SQL. It’s still executing…

     

    what could be the problem? Does it need an output file?

     

    Thanks a lot…

     

    Varsha

     

    From: Tessitura Technical Forum [mailto:forums-technical@tessituranetwork.com] On Behalf Of Ben Gu
    Sent: Tuesday, 7 December 2010 2:07 PM
    To: Varsha Karnik
    Subject: RE: [Tessitura Technical Forum] Zipping a txt file

     

    Hi Varsha,

    I found a very interesting thing in  the xp_cmshell.

    this one work:

    exec master..xp_cmdshell 'c:\winzip\7z.exe a "c:\a\a.zip" "c:\a\a.txt"'

    this one doesn't:

    exec master..xp_cmdshell '"c:\winzip\7z.exe" a "c:\a\a.zip" "c:\a\a.txt"'

    ---

    but

    c:\winzip\7z.exe a "c:\a\a.zip" "c:\a\a.txt"

    and

    "c:\winzip\7z.exe" a "c:\a\a.zip" "c:\a\a.txt"

    both  work in cmd.

    have fun

    Ben

    From: Ben Gu <bounce-bengu4278@tessituranetwork.com>
    Sent: 12/6/2010 8:42:37 PM

    Hi Varsha,

    Good day.

    here is a way to use xp_cmdshell.

     


    steps to run xp_cmdshell.

    step1,


    stored procedure:

    create procedure lp_7zip
    WITH EXECUTE AS 'mynetwork\NetWorkAmdin'

    as
    begin

    exec master..xp_cmdshell 'c:\a\a.bat'  ---it is in sql server c: drive

    end


    step2


    in a.bat file


    --------------------------
    cd\
    "c:\winzip\7z.exe" a "\\mtc.com.au\mtc\Finance\Ben Gu\a\a.zip" "\\mtc.com.au\mtc\Finance\Ben Gu\a\a.txt"
    ------------------------------

    step3


    Credential account

    Credential name:
    ##xp_cmdshell_proxy_account##

    Identity:
    mynetwork\NetWorkAmdin
    passowrd:
    **********
    Comfirm passowrd:
    *********

     

    have fun

     

    Ben




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!




    This message was sent automatically to you by www.tessituranetwork.com because you subscribed to the Tessitura Technical Forum. You may reply to this message to post to the Technical forum or visit the site to search, read and post to the forums. In the interest of keeping the forum posts from becoming cluttered, we encourage you to delete previous message text from your reply before sending. Thank you!

  • Happy ending,

    You are welcome.

    Have fun.

    Ben