为什么我收到“路径不正确”消息 在远程系统上运行批处理文件时出错?

发布于 2024-07-12 05:03:42 字数 655 浏览 7 评论 0原文

我需要从本地计算机在远程系统上运行批处理文件。 使用下面的代码,我收到以下错误:

Path not correct

我有机器的 IP 地址,并且我已将批处理文件指定为公共共享,共享名称为 dsc。

本机的IP地址是16.181.37.28。

这是我的代码。 我知道道路是错误的。 我怎样才能给出准确的路径?

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author padmaja
 */

import java.io.*;
class Test{
public static void main(String arg[]){
try{
String command = "cmd /C start 16.181.37.28/dsc/StartVisTsDataCenterMySql-log.bat";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);

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

I need to run a batch file on a remote system from a local machine. Using the code below, I am getting the following error:

Path not correct

I have the IP address of the machine, and I have given the batch file as public share and share name is dsc.

The IP address of the machine is 16.181.37.28.

Here is my code. I know that the path is wrong. How can I give the exact path?

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author padmaja
 */

import java.io.*;
class Test{
public static void main(String arg[]){
try{
String command = "cmd /C start 16.181.37.28/dsc/StartVisTsDataCenterMySql-log.bat";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(command);

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

北座城市 2024-07-19 05:03:42

您是否尝试在远程计算机或本地计算机上运行脚本? 您的方法将从远程计算机读取文件,但在本地计算机上运行它。

在远程计算机上运行某些内容的常用方法是让远程计算机上有一个进程永久运行并侦听请求。 如果请求到达,此过程将启动您想要运行的批处理文件。

Are you trying to run the script ON THE REMOTE machine or ON YOUR LOCAL machine? Your approach will read the file from the remote machine but run it on your local.

The usual way to get something running on a remote machine is having a process on the remote machine to run permanently and listen for requests. If a request arrives this process will start your batch file you would like to have run.

姐不稀罕 2024-07-19 05:03:42

您在 Windows 上运行,但使用 Posix 路径分隔符。 尝试“cmd /C \\\\16.181.37.28\\dsc\\StartVisTsDataCenterMySql-log.bat”。

You're running on Windows but using Posix paths separators. Try "cmd /C \\\\16.181.37.28\\dsc\\StartVisTsDataCenterMySql-log.bat".

豆芽 2024-07-19 05:03:42

您可以通过创建服务来测试它是否有效:

sc \\16.181.37.28 create StartVisTsDataCenterMySql-Log binPath= "cmd /c \\16.181.37.28\dsc\StartVisTsDataCenterMySql-log.bat"

然后运行它的命令是:

"cmd /c sc \\16.181.37.28 stop StartVisTsDataCenterMySql-Log&sc \\16.181.37.28 start StartVisTsDataCenterMySql-Log"

您需要以以下方式连接到共享管理员(或保存凭据)。 确认有效后,更改为 srvany,因为您将在事件日志中收到错误,否则批处理文件将只允许运行 30 秒。

如果这不是正确的答案,也许您可​​以详细说明真正的要求,并提供一些有关用 Java 重新实现批处理文件是否是现实解决方案的信息。

You can test whether it works by creating a service:

sc \\16.181.37.28 create StartVisTsDataCenterMySql-Log binPath= "cmd /c \\16.181.37.28\dsc\StartVisTsDataCenterMySql-log.bat"

Then the command to run it is:

"cmd /c sc \\16.181.37.28 stop StartVisTsDataCenterMySql-Log&sc \\16.181.37.28 start StartVisTsDataCenterMySql-Log"

You'll need to be connected to the share as an administrator (or have the credentials saved). Once you've confirmed that works, change to srvany, as you will get an error in the event log and the batch file will only be allowed to run for 30 seconds otherwise.

If that's not the right answer, perhaps you can elaborate on the real requirement, and give some information on whether reimplementing the batch file in Java is a realistic solution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文