gpt4 book ai didi

batch-file - 如何从使用 Windows find 命令的 cygwin bash 执行 bat 文件

转载 作者:行者123 更新时间:2023-12-03 07:41:21 25 4
gpt4 key购买 nike

find 命令在 Windows 和 Unix 中的作用完全不同。在 Windows 上,它是一个类似于 fgrep 的实用程序,列出文件中的匹配行;在 Unix 上以及 Cygwin 上,它列出了符合某些条件的文件名。

Cygwin bash 将其标准目录添加到当前路径,因此 bash $PATH 内部通常是 /bin:/usr/bin:/cygdrive/c/WINDOWS/system32:/cygdrive/c/WINDOWS

开始更新以提供更多详细信息

例如,我有许多使用 gnu find 命令的脚本 - 例如用于清除不包含文件的目录树的脚本:

purge-empty-dirs.sh
find . -depth -type d -empty | xargs rmdir -p

我还有一个 bat 文件来启动我的构建,它使用 Windows find 命令,该命令搜索与字符串匹配的行(类似于 gnu grep)。

build.bat
...
dir | find "target"
if errorlevel = 1 goto no_target_dir
...

现在,为了让我的 bash 脚本正常工作,我需要将 /bin 放在 c:\windows\system32 之前的路径中。但是为了运行我的bat文件,我需要将c:\windows\system32放在/bin之前的路径中

一般来说,我们可以声称所有bat文件都应该在bash继承的原始环境中执行,而不是修改后的环境。这有道理吗?

结束更新

应该是这样,但是破坏了从 bash 执行的 bat 文件。解决这个问题的最佳方法是什么?

有没有办法强制 Cygwin 在其启动环境下执行 bat 文件(甚至所有 Windows 可执行文件)?我正在考虑 cmd.exe 的 start/i 行为。我正在考虑编写自己的 cygstart 之类的实用程序来执行此操作,方法是将环境(或至少 $PATH)保存在 .bash_profile/中.bashrc。那有意义吗?

还有其他建议吗?

编辑:另请参阅Start new cmd.exe and NOT inherit environment

最佳答案

如果你chmod +x your.bat它就可以工作。

./your.bat

通过cmd/c运行

已在 Why is it that Cygwin can run .bat scripts? 中回答

关于batch-file - 如何从使用 Windows find 命令的 cygwin bash 执行 bat 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17582778/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com