Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
627 views
in Technique[技术] by (71.8m points)

vbscript - insert a variable to cmd command

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.CreateObject("WScript.Shell") 

LabelName = InputBox("Please Enter Label to check-out:", _
  "Create File")
oShell.run "cmd /K ""c:Program Files (x86)BorlandStarTeam Cross-Platform Client 2008   R2stcmd.exe"" co -p bla:[email protected]:7777/bla/ -is -eol on -o -rp D:ST_test -cfgl  3.1.006"

the input is "LabelName" and it should insert instead of the "3.1.006"

i can't manage to insert this variable, it keeps inserting LabelName instead of the value

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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)BorlandStarTeam Cross-Platform Client 2008   R2stcmd.exe") _
   , "co" _
   , "-p bla:[email protected]:7777/bla/" _
   , "-is -eol on -o -rp" _
   , qq(sLabel) _
))
WScript.Echo sCmd

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

ient 2008   R2stcm
---------^^^

'on second thought' additions -

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

and the quoting will be much easier.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...