Java的如何执行在独立的进程树的批处理文件 [英] How can Java execute batch file in separate process tree

查看:153
本文介绍了Java的如何执行在独立的进程树的批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写我的Java应用程序更新一个mechnism。
我创建一个Windows批处理文件,退出我的程序和批处理文件继续删除我的罐,从远程位置复制新的,开始的罐子。
我的问题:删除+复印件作品,但 - 应用程序将无法启动。
我认为这个问题是我不知道如何使Java在独立的进程树来执行批处理文件。
运行此当:
  调用Runtime.getRuntime()
我打开一个子进程。

I'm writing my Java app a update mechnism. I create a windows batch file,exit my program and the batch file continues to delete my Jar, copy the new one from a remote location, start the jar. My problem: deletion + copy works, BUT - the application won't start. I think the problem is that I don't know how to make Java to execute batch file in separate process tree. when running this: Runtime.getRuntime() I open a child process.

所以我的问题 - 如何执行的Java在独立的进程树的批处理文件

So my question - How can Java execute batch file in separate process tree?

推荐答案

这里是一种解决方法使用CMD作为interminent层:

Here is a workaround that uses cmd as the interminent layer:

public class Main {
    public static void main(String[] args) throws Exception {
        Process p = Runtime.getRuntime().exec("cmd /c c:\\test.bat");
    }
}

在这里test.bat的将包含

where test.bat will contain

@echo off
PING 1.1.1.1 -n 1 -w 5000 >nul
java -jar "[path]"

这篇关于Java的如何执行在独立的进程树的批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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