为什么我不能在Windows上直接用Java执行Cygwin .exe? [英] Why can't I execute a Cygwin .exe directly with Java on Windows?

查看:75
本文介绍了为什么我不能在Windows上直接用Java执行Cygwin .exe?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了Cygwin,但似乎无法直接访问任何命令.例如,由于找不到bash.exe,即使我指定了它的绝对路径,也无法启动下面的过程.我知道它已正确安装,因为我可以在文件资源管理器中看到此路径.但是,搜索任何cygwin文件不会返回任何匹配结果.

I've installed Cygwin but can't seem to access any commands directly. For example, the process below doesn't start due to bash.exe not found even though I'm specifying it's absolute path. I know it's installed correctly since I can see this path in the File Explorer. However, searching for any cygwin file doesn't return any hits which is odd.

ProcessBuilder pb = new ProcessBuilder("C:\\cygwin64\\bin\\bash.exe", "-c", "ls");
Process p = pb.start();

java.io.IOException: Cannot run program "‪C:\cygwin64\bin\bash.exe" (in directory "C:\Users\tyea1\Documents\Log Bundles\latest_PRODXIO01"): CreateProcess error=2, The system cannot find the file specified

如果将cygwin的bin添加到Windows PATH变量中,则可以通过以下方式成功执行"ls"

If I add cygwin's bin to the Windows PATH variable, I can successfully execute "ls" via

ProcessBuilder pb = new ProcessBuilder("cmd", "/c", "ls");
Process p = pb.start();

当它位于PATH中时,我仍然无法直接访问bash.exe.

I still can't access bash.exe directly when it's in the PATH.

我不明白这里发生了什么,为什么我不能直接执行bash.exe.

I don't understand what is going on here and why I can't execute bash.exe directly.

推荐答案

我尚未完全回答自己的问题,但发现了可行的方法.在Windows PATH中使用cygwin \ bin,我的进程生成器字符串为:

I haven't exactly answered my own question but found something that works. With the cygwin \bin in the Windows PATH, my process builder string is:

[cmd,/c,C:\ cygwin64 \ bin \ sh.exe,-c,ls]

[cmd, /c, C:\cygwin64\bin\sh.exe, -c, ls]

这似乎有效.我使用的是sh.exe而不是bash.exe,以便可以使用cygwin的所有bin文件.

This seems to be working. I'm using sh.exe instead of bash.exe so that I can use all of cygwin's bin files.

这篇关于为什么我不能在Windows上直接用Java执行Cygwin .exe?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆