在批处理中获取Cygwin命令的结果

3

问题

我对Cygwin不太熟悉,想从Batch中运行一个Cygwin的shell脚本,并获取返回值。我已经搜索了很多资料,尝试使用C:\cygwin[64]\bin\bash[64].exe,甚至调整了C:\cygwin[64]\Cygwin.bat,但都没有成功。

基本上,我只是想能够从批处理文件中与bash(来自Cygwin)进行交互。如果这对您来说似乎微不足道,请原谅我,因为我对Cygwin还很陌生。无论如何,我还没有找到一个可行的在线解决方案。

示例伪代码:

cygwin-magic "echo shell-command"
#=> shell-command

我尝试过的一些东西

我在谷歌上进行了漫长的搜索,找到了下面这些东西,但是它们都不能满足我的需求。

"C:\cygwin[64]\bin\base[64].exe" /cygdrive/c/users/<me>/desktop/tmp.sh
#=> ZWNobyAiaGVsbG8i

"C:\cygwin[64]\bin\base[64].exe" -d /cygdrive/c/users/<me>/desktop/tmp.sh
#=> y▒h/usr/bin/base[64]: invalid input

"C:\cygwin[64]\bin\base[64].exe" -d -i /cygdrive/c/users/<me>/desktop/tmp.sh
#=> y▒h▒▒e/usr/bin/base[64]: invalid input

"C:\cygwin[64]\bin\base[64].exe" -d -i "echo hello"
#=> /usr/bin/base[64]: echo hello: No such file or directory

# I kind of gave up on all of my other attempts and tried this because why not? Surprise surprise, it didn't work (not that I expected it to).
"C:\cygwin[64]\Cygwin.bat"
echo "hello"

tmp.sh的内容

简单地说,

echo "hello"

目的

我想要从批处理中与bash交互(在Windows上),是因为我想要通过第三方语言与bash进行交互,我已经在第三方语言中规划好了解决方案,但就是无法实现批处理到Cygwin的交互。

注释

  • Windows 7 Home Premium x64
  • Cygwin x64
  • 我在代码中将所有的"64"写成了"[64]",因为我知道32位版本不使用它们。
  • 如果我遗漏了什么或者我的问题有些偏离(过于宽泛或者过于具体等),请评论并让我改正。
1个回答

3
也许你想使用的是"C:\cygwin[64]\bin\basH[64].exe"而不是"C:\cygwin[64]\bin\base[64].exe"

编辑:是的,我犯了一个愚蠢的错误。将其更改为 bash.exe 就可以了! - Mr. Shtuffs
可能不是我得到的,但无论如何,都不重要。 - Mr. Shtuffs
@FirstZero - 看起来并非如此... :) - Magoo
非常抱歉 - 我已经为您的答案投了赞成票并删除了不正确的评论。 - First Zero

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接