0

我有一个 vbs 代码,如:

Message4 = "Please enter Check Out Path"           
 Title4 = "Check Out Path "
 variable1 = InputBox(Message4, Title4,"", 4500, 4500)

 Message5 = "Please enter SVN URL"           
 Title5 = "SVN URL "
 variable2 = InputBox(Message5, Title5, "", 4500, 4500)

 Folder\batchfile.bat"""
 objWshell.Run "batxhfile.bat"

还有名为的批处理文件batchfile.bat

@echo off

Color 42
 echo. [ SVN Updater ]

set Checkout_path=checkout path
set SVN=C:\Program Files\TortoiseSVN\bin
set svn_url=SVN path

 echo. Updating %Checkout_path% to SVN...
"%SVN%\TortoiseProc.exe" /command:checkout /url:"%svn_url%" /path:"%Checkout_path%" /closeonend:2
 echo. done.
 echo.
echo. Operation complete.

现在我想将vbs代码的值variable1variable2从vbs代码传递到批处理文件中checkout pathsvn path我已经尝试了很多方法,但没有成功,直到请帮助。

4

1 回答 1

0

我同意你为什么不简单地从 VBS 调用“TortoiseProc.exe”,但是你可能有理由通过批处理脚本调用。只需将参数从 VBS 传递到批处理中:

`Const ERR_SUCCESS = 0
Const BAT_SCRIPT = "<folder>\batchfile.bat"
Dim oWSH, sCmd, iRC, sVar1, sVar2
Set oWSH = WScipt.CreateObjects("WScript.Shell")
Do While sVar1 <> ""
  sVar1 = InputBox("Please enter Check Out Path", "Check Out Path", 4500, 4500)
Loop
Do While sVar2 <> ""
  sVar2 = InputBox("Please enter SVN URL", "SVN URL", 4500, 4500)
Loop  
sCmd = "cmd.exe /c """ & BAT_SCRIPT & "" "" & sVar1 & "" "" & sVar2 & """" 
WScript.Echo "COMMAND: sCmd"
On Error Resume Next
iRC = oWSH.Run(sCmd, 0, True)
If iRC <> ERR_SUCCESS And Err.Number <> ERR_SUCCESS Then 
  MsgBox "ERROR: [" & Err.Source & "] " & CStr(Err.Number) & " - " & Err.Description & vbCrLf & _
         "       '" & BAT_SCRIPT "' return code = '" & CStr(iRC) & "' from command:" & vbCrLf & _
         "       COMMAND:  " & sCmd, vbOkOnly, "Batch Script Error"
End If
Err.Clear
Set oWSH = Nothing`

您的结果批处理脚本命令应如下调用:
cmd.exe /c "<folder>\batchfile.bat" "<var1>" "<var2>"

确保您的批处理脚本收集参数、删除字符串双引号并正确验证:

`set Checkout_path=%1
set Checkout_path=%Checkout_path:~1,-1%
set svn_url=%2
set svn_url=%svn_url:~1,-1%
if /i "%Checkout_path%" ne "" (
  exit /b 99
)
if /i "%svn_url%" ne "" (
  exit /b 99
)`    

希望这可以帮助 ;)

于 2012-08-12T01:15:44.997 回答