从java运行vbs文件 [英] running a vbs file from java

查看:386
本文介绍了从java运行vbs文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C:/ work / selenium / chrome / 中有一个VBS文件test.vbs,我想从我的Java程序运行它,所以我尝试了这个但是没有运气:

I have a VBS file test.vbs in C:/work/selenium/chrome/ and I want to run it from my Java program, so I tried this but with no luck:

public void test() throws InterruptedException {
   Runtime rt = Runtime.getRuntime();
   try {
      Runtime.getRuntime().exec( "C:/work/selenium/chrome/test.vbs" );
   }
   catch( IOException e ) {
      e.printStackTrace();
   }
}

如果我尝试使用此方法运行某些exe文件它运行良好,但是当我尝试运行VBS文件时,它说不是一个有效的win32应用程序。

If I try to run some exe file with this method it runs well, but when I try to run a VBS file it says "not a valid win32 application".

任何想法如何从Java运行VBS文件?

Any idea how to run a VBS file from Java?

推荐答案

vbs-Script本身不像bat,cmd或exe-Program那样可执行。你必须启动解释器(vbs.exe?)并将脚本作为参数提交:

A vbs-Script isn't natively executable like a bat, cmd or exe-Program. You have to start the interpreter (vbs.exe?) and hand your script over as a parameter:

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

这篇关于从java运行vbs文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆