1

以下行在我的 Windows XP 上的 java 应用程序中运行良好:

Process p = Runtime.getRuntime().exec("msg.exe * this is a test");  

当它在 Windows 7(64 位)上执行时,我收到以下错误:

无法运行程序“msg.exe”:CreateProcess error=2,系统找不到指定的文件

我尝试输入 .exe 的完整路径,但我得到了同样的错误:

Process p = Runtime.getRuntime().exec("c:\\Windows\\System32\\msg.exe * this is a test");

使用 ProcessBuilder 而不是 Runtime 会产生相同的错误:

Process p = new ProcessBuilder("msg.exe * this is a test").start();

我试图通过暂时让每个人完全控制 msg.exe 来排除权限问题,但 Windows 不允许我 - 即使我以管理员身份登录,这些选项也是灰色的。

所以我确认了java进程的用户对msg.exe有读取和执行权限。

我能够从 Windows 7 机器的命令行成功运行命令(作为 java 进程的同一用户)。

在这篇文章的注释中:C# cannot find file specified,有人提到类似的问题,Windows 64-bit machine not found msg.exe from a C# program,所以也许在 Windows 配置方面我需要一些东西做?

有没有办法让 java 应用程序在 Windows 7 上发送网络消息?还是发送有效的网络消息的替代方法?

4

2 回答 2

1

您可能安装了 32 位 Java,不允许在 Windows 7 上启动 64 位程序。如果您安装了 32 位 Java,请升级到 64 位 Java,然后重试。

于 2012-07-27T15:13:48.307 回答
0

请试试:new ProcessBuilder("msg.exe", "* test").start()

于 2012-07-27T15:21:49.323 回答