Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
156 views
in Technique[技术] by (71.8m points)

batch file - How to run a .bat or .vbs script from a particular folder using java programming

I am new to java, I need to execute the run.vbs script from a particular folder say C:UsersApplicationTools un.vbs. I am able to start the script from "windows run" by just giving the location i.e. "C:UsersApplicationTools un.vbs" and clicking on "Enter". But, when i call the same scirpt using:

 Runtime.getRuntime().exec("C:\Users\Application\Tools\run.vbs")

It is giving the error "unable to access the specified file xxxx.war" which is the file vbs script is accessing.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You could/have to load the CMD command for executing BAT files. The syntax is

cmd.exe /c <command name>.

The Java for this command will be:

Runtime.getRuntime().exec("cmd.exe /c <command name>");

For referencing: http://ss64.com/nt/cmd.html

For running .VBS, this may be the way:

cscript <your_script>.vbs

or

wscript <your_script>.vbs 

Java command:

Runtime.getRuntime().exec("cscript <your_script>.vbs");

It is documented here: https://technet.microsoft.com/en-us/library/ee156587.aspx

(My answer is Windows dependent.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...