Executing secondary command in shell.run


  1.    13 Feb 2009 #1
    Han Guest

    Executing secondary command in shell.run


    Hello

    I want to run some commands consecutively with shell. See below,

    set shell=createObject("wscript.shell")
    set fso=createobject("scripting.filesystemobject")
    set f=fso.createTextfile("c:\put.txt", true)

    with f
    .writeline "dir"
    end with

    shell.run "%comspec% /k ""C:\program files\windows azure
    sdk\v1.0\bin\setenv.cmd"" -s:c:\put.txt", 1, true

    f.close

    How do you run the second command "dir" here? Currently the first command
    setenv.cmd runs well. In real world scenario I will add some more commands
    after the "dir".

    Thanks

      My System SpecsSystem Spec

  2.    13 Feb 2009 #2
    Dirk Stegemann Guest

    Re: Executing secondary command in shell.run


    Hi Han,


    > How do you run the second command "dir" here? Currently the first command
    > setenv.cmd runs well. In real world scenario I will add some more commands
    > after the "dir".
    >
    > Thanks
    >
    the scripts genearates a batch on zhe fly. So you should be able to simply add some commands.

    > with f
    > .writeline "dir"
    ..writeline "Some command"

    > end with
    Dirk
      My System SpecsSystem Spec

  3.    13 Feb 2009 #3
    Dirk Stegemann Guest

    Re: Executing secondary command in shell.run



    Sorry its early here in Germany ..


    Correct Code here...

    set shell=createObject("wscript.shell")
    set fso=createobject("scripting.filesystemobject")
    If fso.FileExists("C:\put.cmd") Then _
    fso.deleteFile("C:\put.cmd")
    set f=fso.createTextfile("c:\put.cmd", true)

    with f
    .writeline "dir c:"
    .writeline "dir d:"
    end With

    shell.Run "%comspec% /k ""C:\put.cmd""", 1, true

      My System SpecsSystem Spec

  4.    13 Feb 2009 #4
    Paul Randall Guest

    Re: Executing secondary command in shell.run



    "Han" <hp4444@xxxxxx> wrote in message
    news:14E4F8BF-6E79-4A9E-AE02-65E84D0CBDBC@xxxxxx

    > Hello
    >
    > I want to run some commands consecutively with shell. See below,
    >
    > set shell=createObject("wscript.shell")
    > set fso=createobject("scripting.filesystemobject")
    > set f=fso.createTextfile("c:\put.txt", true)
    >
    > with f
    > .writeline "dir"
    > end with
    >
    > shell.run "%comspec% /k ""C:\program files\windows azure
    > sdk\v1.0\bin\setenv.cmd"" -s:c:\put.txt", 1, true
    >
    > f.close
    >
    > How do you run the second command "dir" here? Currently the first command
    > setenv.cmd runs well. In real world scenario I will add some more commands
    > after the "dir".
    >
    > Thanks
    On most WXP systems, there is a Help & Support item available from the start
    button. Help & support typically links to ntcmds.chm for command-line
    related queries. Unfortunately, on many computers such as those made by
    Compaq/HP, they make it impossible to run ntcmds.chm separately from the
    help and support center, so you can't use the CHM search facility to
    directly find what you want. My Compaq's help & support center is
    particularly unhelpful, in that when searching for "command shell overview",
    I get only one hit: MS-DOS overview. We all know that there is no MS-DOS in
    WXP.

    Anyhow, on a systems where the manufacturer hasn't messed up ntcmds.chm, it
    contains a section called 'Command Shell Overview", and it contains info on
    running multiple commands.

    The & character is the command separator.
    Syntax:
    command1 & command2

    Of course, there may be times when you want to run command2 only if command1
    runs successfully. For this, use two ampersands:
    command1 && command2

    There may also be times when you want to run command2 only if command 1
    fails. For this, use two pipe characters:
    command1 || command2

    You might also want to group or nest multiple commands. For this use
    parentheses:
    (command1 & command2)

    Parameters for the commands can be separated by semicolons or commas:
    command1 parameter1;parameter2

    HTH

    -Paul Randall


      My System SpecsSystem Spec

  5.    13 Feb 2009 #5
    Tomy Guest

    Re: Executing secondary command in shell.run


    On Feb 13, 5:47 pm, "Paul Randall" <paul...@xxxxxx> wrote:

    > "Han" <hp4...@xxxxxx> wrote in message
    >
    > news:14E4F8BF-6E79-4A9E-AE02-65E84D0CBDBC@xxxxxx
    >
    >
    >

    > > Hello
    >

    > > I want to run some commands consecutively with shell. See below,
    >

    > > set shell=createObject("wscript.shell")
    > > set fso=createobject("scripting.filesystemobject")
    > > set f=fso.createTextfile("c:\put.txt", true)
    >

    > > with f
    > > .writeline "dir"
    > > end with
    >

    > > shell.run "%comspec% /k ""C:\program files\windows azure
    > > sdk\v1.0\bin\setenv.cmd"" -s:c:\put.txt", 1, true
    >

    > > f.close
    >

    > > How do you run the second command "dir" here? Currently the first command
    > > setenv.cmd runs well. In real world scenario I will add some more commands
    > > after the "dir".
    >

    > > Thanks
    >
    > On most WXP systems, there is a Help & Support item available from the start
    > button. Help & support typically links to ntcmds.chm for command-line
    > related queries. Unfortunately, on many computers such as those made by
    > Compaq/HP, they make it impossible to run ntcmds.chm separately from the
    > help and support center, so you can't use the CHM search facility to
    > directly find what you want. My Compaq's help & support center is
    > particularly unhelpful, in that when searching for "command shell overview",
    > I get only one hit: MS-DOS overview. We all know that there is no MS-DOS in
    > WXP.
    >
    > Anyhow, on a systems where the manufacturer hasn't messed up ntcmds.chm, it
    > contains a section called 'Command Shell Overview", and it contains info on
    > running multiple commands.
    >
    > The & character is the command separator.
    > Syntax:
    > command1 & command2
    >
    > Of course, there may be times when you want to run command2 only if command1
    > runs successfully. For this, use two ampersands:
    > command1 && command2
    >
    > There may also be times when you want to run command2 only if command 1
    > fails. For this, use two pipe characters:
    > command1 || command2
    >
    > You might also want to group or nest multiple commands. For this use
    > parentheses:
    > (command1 & command2)
    >
    > Parameters for the commands can be separated by semicolons or commas:
    > command1 parameter1;parameter2
    >
    > HTH
    >
    > -Paul Randall
    Yes. Here's the demo code

    option explicit
    Dim strCmd1, strCmd2, strCmd3
    Dim oShell

    Set oShell = WScript.CreateObject ("WScript.shell")
    strCmd1 = "dir /x"
    strCmd2 = "dir /w"
    strCmd3 = "pause"
    oShell.Run "%comspec% /c" & strCmd1 & " && " & strCmd2 & " && " &
    strCmd3,1,true
    Set oShell = Nothing
      My System SpecsSystem Spec

  6.    13 Feb 2009 #6
    Todd Vargo Guest

    Re: Executing secondary command in shell.run


    Han wrote:

    > Hello
    >
    > I want to run some commands consecutively with shell. See below,
    >
    > set shell=createObject("wscript.shell")
    > set fso=createobject("scripting.filesystemobject")
    > set f=fso.createTextfile("c:\put.txt", true)
    >
    > with f
    > .writeline "dir"
    > end with
    >
    > shell.run "%comspec% /k ""C:\program files\windows azure
    > sdk\v1.0\bin\setenv.cmd"" -s:c:\put.txt", 1, true
    >
    > f.close
    >
    > How do you run the second command "dir" here? Currently the first command
    > setenv.cmd runs well. In real world scenario I will add some more commands
    > after the "dir".
    Change put.txt to put.cmd, write all commands to it, then run put.cmd
    instead.

    set shell=createObject("wscript.shell")
    set fso=createobject("scripting.filesystemobject")
    set f=fso.createTextfile("c:\put.cmd", true)

    with f
    .writeline "@echo off"
    .writeline "call ""C:\program files\windows azure
    sdk\v1.0\bin\setenv.cmd"""
    .writeline "dir"
    .writeline "other commands"
    end with

    shell.run "c:\put.cmd", 1, true

    f.close

    --
    Todd Vargo
    (Post questions to group only. Remove "z" to email personal messages)

      My System SpecsSystem Spec

  7.    15 Feb 2009 #7
    Han Guest

    Re: Executing secondary command in shell.run


    Thank you very much Dirk, Paul, Tomy, and Todd Vargo.
    I am trying one by one all of your recommandations.
    They seem to help me a lot.

    I will let you know the result. Currently Simple commands like "dir"
    perfectly works. Not that the colud service command lines per se. I am happy
    to see the legendary kindness of this NG persists.

    "Han" <hp4444@xxxxxx> 님이 다음 메시지를 작성했습니다.
    news:14E4F8BF-6E79-4A9E-AE02-65E84D0CBDBC@xxxxxx

    > Hello
    >
    > I want to run some commands consecutively with shell. See below,
    >
    > set shell=createObject("wscript.shell")
    > set fso=createobject("scripting.filesystemobject")
    > set f=fso.createTextfile("c:\put.txt", true)
    >
    > with f
    > .writeline "dir"
    > end with
    >
    > shell.run "%comspec% /k ""C:\program files\windows azure
    > sdk\v1.0\bin\setenv.cmd"" -s:c:\put.txt", 1, true
    >
    > f.close
    >
    > How do you run the second command "dir" here? Currently the first command
    > setenv.cmd runs well. In real world scenario I will add some more commands
    > after the "dir".
    >
    > Thanks
      My System SpecsSystem Spec

  8.    16 Feb 2009 #8
    Han Guest

    Re: Executing secondary command in shell.run


    Hello again

    I think I am nearly at there except miner issue.

    Set oShell = WScript.CreateObject ("WScript.shell")

    strCmd1 = """C:\program files\windows azure sdk\v1.0\bin\setenv.cmd"""
    strCmd2 = "cspack AAA.XXX"
    strCmd3 = "pause"

    oShell.Run "%comspec% /k" & _
    strCmd1 & " && " & _
    "cd .. && " & _
    "cd .. && " & _
    "cd .. && " & _
    "cd .. && " & _
    strCmd2 & " && " & _
    strCmd3, 1, true

    Above script works fine when I do "AAA.XXX". Works either with
    "AAA\BBB.XXX".
    But doesn't work with "AAA BBB\CCC.XXX". i.e., when one of directoris has
    space.

    How do you supress the spaces in such a situation? I tried everything I can
    imagine: every kind of single or double quotations.


    "Han" <hp4444@xxxxxx> 님이 다음 메시지를 작성했습니다.
    news:14E4F8BF-6E79-4A9E-AE02-65E84D0CBDBC@xxxxxx

    > Hello
    >
    > I want to run some commands consecutively with shell. See below,
    >
    > set shell=createObject("wscript.shell")
    > set fso=createobject("scripting.filesystemobject")
    > set f=fso.createTextfile("c:\put.txt", true)
    >
    > with f
    > .writeline "dir"
    > end with
    >
    > shell.run "%comspec% /k ""C:\program files\windows azure
    > sdk\v1.0\bin\setenv.cmd"" -s:c:\put.txt", 1, true
    >
    > f.close
    >
    > How do you run the second command "dir" here? Currently the first command
    > setenv.cmd runs well. In real world scenario I will add some more commands
    > after the "dir".
    >
    > Thanks
      My System SpecsSystem Spec

  9.    16 Feb 2009 #9
    Al Dunbar Guest

    Re: Executing secondary command in shell.run



    "Han" <hp4444@xxxxxx> wrote in message
    news:59D45276-1399-40F9-8B0F-651B6E7F4B36@xxxxxx

    > Hello again
    >
    > I think I am nearly at there except miner issue.
    >
    > Set oShell = WScript.CreateObject ("WScript.shell")
    >
    > strCmd1 = """C:\program files\windows azure sdk\v1.0\bin\setenv.cmd"""
    > strCmd2 = "cspack AAA.XXX"
    > strCmd3 = "pause"
    >
    > oShell.Run "%comspec% /k" & _
    > strCmd1 & " && " & _
    > "cd .. && " & _
    > "cd .. && " & _
    > "cd .. && " & _
    > "cd .. && " & _
    > strCmd2 & " && " & _
    > strCmd3, 1, true
    >
    > Above script works fine when I do "AAA.XXX". Works either with
    > "AAA\BBB.XXX".
    > But doesn't work with "AAA BBB\CCC.XXX". i.e., when one of directoris has
    > space.
    >
    > How do you supress the spaces in such a situation? I tried everything I
    > can imagine: every kind of single or double quotations.
    You don't want to suppress the spaces because they are there in the path to
    the file in question. What you want to do is to represent them. You have
    already done that for the batch file, whose location you give as:

    strCmd1 = """C:\program files\windows azure sdk\v1.0\bin\setenv.cmd"""

    In a quoted literal string you represent a literal double quote character by
    including two double quote characters. Perhaps all you need do is to change
    this:

    strCmd2 = "cspack AAA.XXX"

    to this:

    strCmd2 = """cspack AAA.XXX"""

    /Al


    > "Han" <hp4444@xxxxxx> 님이 다음 메시지를 작성했습니다.
    > news:14E4F8BF-6E79-4A9E-AE02-65E84D0CBDBC@xxxxxx

    >> Hello
    >>
    >> I want to run some commands consecutively with shell. See below,
    >>
    >> set shell=createObject("wscript.shell")
    >> set fso=createobject("scripting.filesystemobject")
    >> set f=fso.createTextfile("c:\put.txt", true)
    >>
    >> with f
    >> .writeline "dir"
    >> end with
    >>
    >> shell.run "%comspec% /k ""C:\program files\windows azure
    >> sdk\v1.0\bin\setenv.cmd"" -s:c:\put.txt", 1, true
    >>
    >> f.close
    >>
    >> How do you run the second command "dir" here? Currently the first command
    >> setenv.cmd runs well. In real world scenario I will add some more
    >> commands after the "dir".
    >>
    >> Thanks
    >

      My System SpecsSystem Spec

  10.    16 Feb 2009 #10
    Han Guest

    Re: Executing secondary command in shell.run


    Thanks Al Dunbar

    Exactly. Representation instead of suppress.

    Anyway. Your recommandation was my first try without success.

    strCmd1 = """C:\program files\windows azure sdk\v1.0\bin\setenv.cmd"""

    works as expected. But,

    strCmd2 = """cspack AAA BBB\CCC.XXX"""

    doesn't work with error message,

    "c:\Program is neither executable file nor batch file ..."

    The second command with double double quotation marks definitely affects the
    first commands here. I have no idea why they are related when the second has
    double double quotation marks.

    On the other hand, when the second has no double double quotations error
    message is,

    "no file named c:\BBB\CCC.XXX ..."

    Which wrongly suppress the "AAA " part. I worry that can be caused from the
    program "cspack.exe", which is the worst case.


    "Al Dunbar" <alandrub@xxxxxx> 님이 다음 메시지를 작성했습니다.
    news:%23MRszTDkJHA.5124@xxxxxx

    >
    > "Han" <hp4444@xxxxxx> wrote in message
    > news:59D45276-1399-40F9-8B0F-651B6E7F4B36@xxxxxx

    >> Hello again
    >>
    >> I think I am nearly at there except miner issue.
    >>
    >> Set oShell = WScript.CreateObject ("WScript.shell")
    >>
    >> strCmd1 = """C:\program files\windows azure sdk\v1.0\bin\setenv.cmd"""
    >> strCmd2 = "cspack AAA.XXX"
    >> strCmd3 = "pause"
    >>
    >> oShell.Run "%comspec% /k" & _
    >> strCmd1 & " && " & _
    >> "cd .. && " & _
    >> "cd .. && " & _
    >> "cd .. && " & _
    >> "cd .. && " & _
    >> strCmd2 & " && " & _
    >> strCmd3, 1, true
    >>
    >> Above script works fine when I do "AAA.XXX". Works either with
    >> "AAA\BBB.XXX".
    >> But doesn't work with "AAA BBB\CCC.XXX". i.e., when one of directoris has
    >> space.
    >>
    >> How do you supress the spaces in such a situation? I tried everything I
    >> can imagine: every kind of single or double quotations.
    >
    > You don't want to suppress the spaces because they are there in the path
    > to the file in question. What you want to do is to represent them. You
    > have already done that for the batch file, whose location you give as:
    >
    > strCmd1 = """C:\program files\windows azure sdk\v1.0\bin\setenv.cmd"""
    >
    > In a quoted literal string you represent a literal double quote character
    > by including two double quote characters. Perhaps all you need do is to
    > change this:
    >
    > strCmd2 = "cspack AAA.XXX"
    >
    > to this:
    >
    > strCmd2 = """cspack AAA.XXX"""
    >
    > /Al
    >
    >

    >> "Han" <hp4444@xxxxxx> 님이 다음 메시지를 작성했습니다.
    >> news:14E4F8BF-6E79-4A9E-AE02-65E84D0CBDBC@xxxxxx

    >>> Hello
    >>>
    >>> I want to run some commands consecutively with shell. See below,
    >>>
    >>> set shell=createObject("wscript.shell")
    >>> set fso=createobject("scripting.filesystemobject")
    >>> set f=fso.createTextfile("c:\put.txt", true)
    >>>
    >>> with f
    >>> .writeline "dir"
    >>> end with
    >>>
    >>> shell.run "%comspec% /k ""C:\program files\windows azure
    >>> sdk\v1.0\bin\setenv.cmd"" -s:c:\put.txt", 1, true
    >>>
    >>> f.close
    >>>
    >>> How do you run the second command "dir" here? Currently the first
    >>> command setenv.cmd runs well. In real world scenario I will add some
    >>> more commands after the "dir".
    >>>
    >>> Thanks
    >>
    >
    >
      My System SpecsSystem Spec

Page 1 of 2 12 LastLast
Executing secondary command in shell.run

Similar Threads
Thread Forum
Shell Command
How to Use the Vista Shell Command This will show you how to use the Shell command to enable you to quickly open a hard to find folder or object....
Tutorials
Executing a external tool command with arguments
Hi, In Powershell is there anything where i can call something similar to this exec("EXE then Pass all my arguments ...") where i can pass all...
PowerShell
WScript.Shell echo command?
I'm trying to run a program within vbs using WScript.Shell that requires a pipe. The command i need to run is echo <text> | clip But when i...
VB Script
Trouble executing a command
Hello all This is my DOS command: "C:\Program Files\7-Zip\7z" a -tzip \\server\dats\dailyDats.zip db_20080522.dat ....which works fine. In...
PowerShell
Invoke-Expression executing a command with spaces
I got confused with using quotes in invoke-expression command. I am trying to run the following command from powershell..The command takes a...
PowerShell
Executing Power Shell Scripts from Windows Shell
Typing powershell "D:\PowerShell Examples\TempScript.ps1" on the cmd prompt, gives an error that, The term 'D:\PowerShell' is not recognized as a...
PowerShell
Executing a command like run [command]
Is there a way to execute a command in the same way as typing it into the start-run box? basically I am looking to open a webpage using powershell...
PowerShell

Our Sites
  • Ten Forums
  • Eight Forums
  • Seven Forums
  • Help Me Bake
  • Site Links
  • Contact Us
  • Privacy and Cookies
  • About Us
    Windows Vista Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

    Designer Media Ltd
    All times are GMT -5. The time now is 09:27.
    .