use*_*162 10 java vbscript runtime
我有一个VBS文件test.vbs C:/work/selenium/chrome/,我想从我的Java程序运行它,所以我尝试了这个,但没有运气:
public void test() throws InterruptedException {
Runtime rt = Runtime.getRuntime();
try {
Runtime.getRuntime().exec( "C:/work/selenium/chrome/test.vbs" );
}
catch( IOException e ) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
如果我尝试使用此方法运行某些exe文件,它运行良好,但是当我尝试运行VBS文件时,它说"不是有效的win32应用程序".
知道如何从Java运行VBS文件吗?
小智 12
public static void main(String[] args) {
try {
Runtime.getRuntime().exec( "wscript D:/Send_Mail_updated.vbs" );
}
catch( IOException e ) {
System.out.println(e);
System.exit(0);
}
}
Run Code Online (Sandbox Code Playgroud)
这工作正常,Send_Mail_updated.vbs我的VBS文件的名称
vbs 脚本本身并不像 bat、cmd 或 exe 程序那样可执行。您必须启动解释器(vbs.exe?)并将脚本作为参数传递:
String script = "C:\\work\\selenium\\chrome\\test.vbs";
// search for real path:
String executable = "C:\\windows\\...\\vbs.exe";
String cmdArr [] = {executable, script};
Runtime.getRuntime ().exec (cmdArr);
Run Code Online (Sandbox Code Playgroud)