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

问题描述

我想在服务器上远程执行一个bat文件
\\ testserver \ someFolderName \ test.bat
我正在使用流程构建器并希望使用
procbuilder.directory(....),
来链接目录但不能成功。

I want to execute a bat file located remotely on server\\testserver\someFolderName\test.bat.I am using process builder and wanted to chande the directory withprocbuilder.directory(....),but could not succeed.

感谢任何帮助。谢谢

推荐答案

这是我们目前正在使用的工作代码:

This is working code that we are using currently:

try {
   ProcessBuilder launcher = new ProcessBuilder();
   Map<String, String> environment = launcher.environment();
   launcher.redirectErrorStream(true);
   launcher.directory(new File("\\\\<your remote computer name>\\TIERS\\DEV1\\RP\\VISUAL_BASIC\\"));

   environment.put("name", "var");
   launcher.command("your.exe");
   Process p = launcher.start(); // And launch a new process

} catch (Exception e){
   e.printStackTrace();
}

这篇关于远程执行批处理文件java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 03:59