insert a variable to cmd command

后端 未结 2 531
孤城傲影
孤城傲影 2020-12-02 03:30

I need to get a input from the user (string) and insert it in a cmd command,

Set oShell = WScript.CreateObject(\"WScript.Shell\")  
Set LabelName = WScript.         


        
相关标签:
2条回答
  • 2020-12-02 03:40

    Build your command in a more structured way - e.g:

    Option Explicit
    
    Function qq(s) : qq = """" & s & """" : End Function
    
    Dim sLabel : sLabel   = "default label"
    Dim oWAU   : Set oWAU = WScript.Arguments.Unnamed
    If 1 <= oWAU.Count Then sLabel = oWAU(0)
    Dim sCmd   : sCmd     = Join(Array( _
         "%comspec%" _
       , "/K" _
       , qq("c:\Program Files (x86)\Borland\StarTeam Cross-Platform Client 2008   R2\stcmd.exe") _
       , "co" _
       , "-p bla:bla123@123.com:7777/bla/" _
       , "-is -eol on -o -rp" _
       , qq(sLabel) _
    ))
    WScript.Echo sCmd
    

    and display the extra variable sCmd. Fixing (possible) blunders -

    ient 2008   R2\stcm
    ---------^^^
    

    'on second thought' additions -

    , qq(sLabel) _
    ==>
    , qq("D:\ST_test") _
    , "-cfgl" _
    , sLabel _
    

    and the quoting will be much easier.

    0 讨论(0)
  • 2020-12-02 03:41

    LabelName doesn't need to be a shell object, as it's just a string. Then concatenate the string onto the run command and you are done.

    Set oShell = WScript.CreateObject("WScript.Shell")  
    Dim LabelName
    
    LabelName = InputBox("Please Enter Label to check-out:", _
      "Create File")
    oShell.run "cmd /K ""c:\Program Files (x86)\Borland\StarTeam Cross-Platform Client 2008 R2\stcmd.exe"" co -p bla:bla123@123.com:7777/bla/ -is -eol on -o -rp D:\ST_test -cfgl  " & LabelName
    
    0 讨论(0)
提交回复
热议问题