Java、本机应用程序和全局路径

发布于 2024-11-24 02:17:18 字数 532 浏览 4 评论 0原文

我需要执行一个批处理文件(在 Java 6 中)并为此使用以下代码:

final String command = "C:\Ruby191\bin\mygem.bat inputfile.dat";
final File parent = new File(aParentDir);
Process proc;
proc = aRuntime.exec(command, null, parent);

但我得到这个异常:

...Exception: java.io.IOException: Cannot run program "
C:\Ruby191\bin\mygem.bat" (in directory "src\test\resources\...
"): CreateProcess error=267, Directory name invalid

有问题的批处理文件存在于指定的目录中。

我的代码有什么问题?

I need to execute a batch file (in Java 6) and use following code for this:

final String command = "C:\Ruby191\bin\mygem.bat inputfile.dat";
final File parent = new File(aParentDir);
Process proc;
proc = aRuntime.exec(command, null, parent);

But I get this exception:

...Exception: java.io.IOException: Cannot run program "
C:\Ruby191\bin\mygem.bat" (in directory "src\test\resources\...
"): CreateProcess error=267, Directory name invalid

The batch file in question exists in the specified directory.

What is wrong in my code?

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

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

发布评论

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

评论(1

白云悠悠 2024-12-01 02:17:18

尝试使用双反斜杠 \\ 或单斜杠 / 而不是单反斜杠。还要检查当前目录名称。

Try using double backslashes \\ or single slashes / instead of single backslashes. Check current directory name too.

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