0

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)\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  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

Newton
  • 41
  • 1
  • 8
  • 1
    So what´s your question? – TheBlastOne Mar 18 '14 at 12:17
  • This is a common mistake, which is covered in the [tag wiki](http://stackoverflow.com/tags/vbscript/info). VBScript doesn't expand variables inside strings. Instead you need to concatenate the variable with the two halves of the string. – Ansgar Wiechers Mar 18 '14 at 13:44

2 Answers2

0

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.

Ekkehard.Horner
  • 38,498
  • 2
  • 45
  • 96
  • sorry, didn't understand this one, can you explain it ? – Newton Mar 18 '14 at 15:49
  • -1 answer was confusing, didnt address the original issue beyond the source code, with no explanation of the improvised execution. – Rich Mar 25 '14 at 00:33
0

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
Rich
  • 4,134
  • 3
  • 26
  • 45
  • Ok, but in this piece of code, this command doesn't run, need quotes somewhere – Newton Mar 19 '14 at 10:33
  • most likely was the triple space between 2008 and R2. Give that a try. Other than that, you get the general idea of it. – Rich Mar 19 '14 at 14:07