Professional Web Applications Themes

CmdExec: Multiple Commands - Microsoft SQL / MS SQL Server

I am trying to execute multiple commands in a SQL Server job CmdExec step, e.g. cmd.exe param1 param2 cmd.exe param3 param4 The step runs successfully, but only the first cmd.exe executes; everything after is ignored. I have got around this by using xp_cmdshell and Transact- SQL script, e.g. xp_cmdshell 'cmd.exe param1 param2' xp_cmdshell 'cmd.exe param3 param4' cmd.exe runs twice in this case. But do I really need to do this? None of the doentation I've looked at states explicitly that there is a limit of one command, and in one case it suggests multiple commands are possible. Help!...

  1. #1

    Default CmdExec: Multiple Commands

    I am trying to execute multiple commands in a SQL Server
    job CmdExec step, e.g.

    cmd.exe param1 param2
    cmd.exe param3 param4

    The step runs successfully, but only the first cmd.exe
    executes; everything after is ignored.

    I have got around this by using xp_cmdshell and Transact-
    SQL script, e.g.

    xp_cmdshell 'cmd.exe param1 param2'
    xp_cmdshell 'cmd.exe param3 param4'

    cmd.exe runs twice in this case.

    But do I really need to do this? None of the
    doentation I've looked at states explicitly that there
    is a limit of one command, and in one case it suggests
    multiple commands are possible. Help!
    Leo Bateman Guest

  2. #2

    Default Re: CmdExec: Multiple Commands

    You can concatenate commands in the commandshell with &. So dir c:\ & dir
    c:\temp will give you 2 directory listings for example and param1 param2 &
    param3 param4 will give you the results you want. You don't need to call
    cmd.exe from inside a CmdExe jobstep or xp_cmdhell, they call cmd.exe
    already.

    Similar to &, && will only run the second command if the first command
    succeeded, and there are a few other handy symbols you can find in Windows
    help.

    --
    Jacco Schalkwijk MCDBA, MCSD, MCSE
    Database Administrator
    Eurostop Ltd.


    "Leo Bateman" <leo.batemansiemensnospam.com> wrote in message
    news:693f01c3408e$3ce2dc20$3101280aphx.gbl...
    > I am trying to execute multiple commands in a SQL Server
    > job CmdExec step, e.g.
    >
    > cmd.exe param1 param2
    > cmd.exe param3 param4
    >
    > The step runs successfully, but only the first cmd.exe
    > executes; everything after is ignored.
    >
    > I have got around this by using xp_cmdshell and Transact-
    > SQL script, e.g.
    >
    > xp_cmdshell 'cmd.exe param1 param2'
    > xp_cmdshell 'cmd.exe param3 param4'
    >
    > cmd.exe runs twice in this case.
    >
    > But do I really need to do this? None of the
    > doentation I've looked at states explicitly that there
    > is a limit of one command, and in one case it suggests
    > multiple commands are possible. Help!

    Jacco Schalkwijk Guest

Similar Threads

  1. ssi commands in DW
    By ja4ck in forum Macromedia Dynamic HTML
    Replies: 7
    Last Post: October 31st, 01:25 AM
  2. Key commands
    By mariadrakis@gmail.com in forum Adobe Indesign Macintosh
    Replies: 0
    Last Post: September 29th, 06:31 PM
  3. multiple grids on one page - use single Update/Edit/Cancel commands
    By Iain Porter in forum ASP.NET Data Grid Control
    Replies: 3
    Last Post: December 16th, 10:13 AM
  4. Commands question
    By Bill Ray in forum Macromedia Fireworks
    Replies: 13
    Last Post: October 18th, 06:38 PM
  5. executing multiple shell commands via one exec()-call
    By Falk Schneider in forum PHP Development
    Replies: 1
    Last Post: July 15th, 06:20 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139