如何通过带有多个参数的 vbscript 运行 java 编程?
How to run java program via vbscript with multiple arguments?
我想运行一个简单的java程序,使用VB脚本解析参数。
这是我的VB脚本代码
Sub Button1_Click()
Set WshShell = CreateObject("WScript.Shell")
Dim jar
Dim location
Dim dictionary
Set dictionary = CreateObject("Scripting.Dictionary")
jar = "C:\Users\Documents\ExP.jar"
location = "C:\Users\Documents\TestProject"
Set WshShellExec = WshShell.Exec("java -jar " & Chr(34) & jar & Chr(34) & location & Chr(34))
End Sub
这是我要传递参数的 java class
public static void main(String[] args) {
ReadTestScripts readTestScripts = new ReadTestScripts(args[3]);
//location ="C:\Users\Documents\TestProject" - want to pass this path to java programme
readTestScripts.showResult();
}
当我将位置作为 VB脚本参数
传递时,我没有得到预期的输出
您正在连接要执行的命令,但没有在参数之间留下 spaces,所以目前如果您调试传递给 Exec()
的命令,它将看起来像;
java -jar "C:\Users\Documents\ExP.jar""C:\Users\Documents\TestProject"
解决方法是在 jar
和 location
之间添加一个串联的 space。
Sub Button1_Click()
Set WshShell = CreateObject("WScript.Shell")
Dim a
Dim location
Dim dictionary
Set dictionary = CreateObject("Scripting.Dictionary")
jar = "C:\Users\Documents\ExP.jar"
location = "C:\Users\Documents\TestProject"
Set WshShellExec = WshShell.Exec("java -jar """ & jar & """ """ & location & """")
End Sub
这将产生命令
java -jar "C:\Users\Documents\ExP.jar" "C:\Users\Documents\TestProject"
注意,将 Chr(34)
替换为双引号的正确转义方法,即加倍。
有用的链接
- Launch programs whose path contains spaces
我想运行一个简单的java程序,使用VB脚本解析参数。
这是我的VB脚本代码
Sub Button1_Click()
Set WshShell = CreateObject("WScript.Shell")
Dim jar
Dim location
Dim dictionary
Set dictionary = CreateObject("Scripting.Dictionary")
jar = "C:\Users\Documents\ExP.jar"
location = "C:\Users\Documents\TestProject"
Set WshShellExec = WshShell.Exec("java -jar " & Chr(34) & jar & Chr(34) & location & Chr(34))
End Sub
这是我要传递参数的 java class
public static void main(String[] args) {
ReadTestScripts readTestScripts = new ReadTestScripts(args[3]);
//location ="C:\Users\Documents\TestProject" - want to pass this path to java programme
readTestScripts.showResult();
}
当我将位置作为 VB脚本参数
传递时,我没有得到预期的输出您正在连接要执行的命令,但没有在参数之间留下 spaces,所以目前如果您调试传递给 Exec()
的命令,它将看起来像;
java -jar "C:\Users\Documents\ExP.jar""C:\Users\Documents\TestProject"
解决方法是在 jar
和 location
之间添加一个串联的 space。
Sub Button1_Click()
Set WshShell = CreateObject("WScript.Shell")
Dim a
Dim location
Dim dictionary
Set dictionary = CreateObject("Scripting.Dictionary")
jar = "C:\Users\Documents\ExP.jar"
location = "C:\Users\Documents\TestProject"
Set WshShellExec = WshShell.Exec("java -jar """ & jar & """ """ & location & """")
End Sub
这将产生命令
java -jar "C:\Users\Documents\ExP.jar" "C:\Users\Documents\TestProject"
注意,将 Chr(34)
替换为双引号的正确转义方法,即加倍。
有用的链接
- Launch programs whose path contains spaces