我有一个类似的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.
现在我想将variable1
和variable2
的值从vbs代码传递到批处理文件,代替checkout path
和svn path
我尝试了很多方法但是没有成功,直到PLZ帮助。
答案 0 :(得分: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
)`
希望这会有所帮助;)