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.
Any help is appreciated. Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
过去,我用 PSExec 快速而肮脏地完成了这
件事从您的程序中将其作为自己的进程启动,并使用所需的参数来访问远程计算机上的批处理。
In the past I've done it quick and dirty with PSExec
Just start that from your program as its own process with the required arguments to gain access to the batch on the remote computer.
我不认为您可以为 ProcessBuilder 执行 UNC 路径,但在任何情况下这并不重要。
要运行 .bat 文件,您需要运行 Windows 命令 shell 并让它执行 .bat 文件,并且命令 shell 不支持 UNC 路径...解决方法是像这样运行命令:
本质上,您告诉 cmd 提示符将远程文件夹安装为临时驱动器 (pushd \testserver\someFolderName),运行 test.bat,然后卸载临时驱动器 (popd)。
I don't think you can do UNC paths for the ProcessBuilder, but it doesn't really matter in any case.
To run a .bat file, you need to run a windows command shell and have that execute the .bat file, and the command shell doesn't support UNC paths... The way around it is to run your command like this:
Essentially, you're telling the cmd prompt to mount your remote folder as a temporary drive (pushd \testserver\someFolderName), run test.bat and then unmount the temporary drive (popd).
这是我们当前正在使用的工作代码:
This is working code that we are using currently:
它也可以在 java 中运行,如下所示:
it also works in java as below: