java - How to find whether vbscript is running or not
问题描述
import java.io.IOException;
public class runvbs {
public static void RunVBs(String jobName) throws InterruptedException, IOException {
// TODO Auto-generated method stub
try {
String currentDir = System.getProperty("user.dir");
//Execute the vbscript name which is passed in this method.
//Generally it is runmfjob.vbs is the vbscript to run as a pre-requisite.
Runtime.getRuntime().exec("wscript " + currentDir + "\\vbscript\\" + jobName + ".vbs");
boolean statusofjob;
//Every 60 seconds monitor the jobs and print the job is completed or not.
//Do loop executes until the job is completed.
do {
System.out.println("Mainframe Job is running and waiting to complete it");
Thread.sleep(60000);
} while (DataGenerator.getstatusofJob() == true);
System.out.println("Vbscript is completed");
} catch (InterruptedException e) {
System.out.println(e);
System.exit(0);
}
}
}
public static boolean getstatusofJob() {
boolean runflag = false;
try {
String line;
String pidInfo = "";
Process p = Runtime.getRuntime().exec(System.getenv("windir") + "\\system32\\" + "tasklist.exe");
BufferedReader input = new BufferedReader(new InputStreamReader(p.getInputStream()));
// System.out.println(input);
while ((line = input.readLine()) != null) {
pidInfo += line;
}
input.close();
if (pidInfo.contains("wscript.exe")) {
// System.out.println("Firefox is running");
runflag = true;
} else {
// System.out.println("Firefox is NOT running");
runflag = false;
}
}
catch (IOException e) {
e.printStackTrace();
}
return runflag;
}
This sometimes returns correct but not all the time. Sometimes my vbscript is completed, but it is still monitoring. Can any one help to get this to work everytime?
解决方案
推荐阅读
- mysql - ErrCode 与“选择进入带有变量的 Outfile” - 混淆权限
- angular - 键入'AngularFireAction
>[]' 不可分配给类型 'Product[]' - android - AlertDialog 未显示在 Android 的 runOnUIThread 中
- performance - 糟糕的 CSS 动画性能 - 没有浏览器绘制
- c# - 计算大量 GPS 坐标之间的成对路由距离
- javascript - 需要在 ReactJS 中的 render() 之前执行函数
- java - 性能调优 - 数据库调用次数
- android - Unity Sprites 图像未更新
- matlab - 将矩阵列转换为单位向量的快速方法
- machine-learning - 为什么要为自适应优化算法设置学习率?