简体   繁体   English

如何将 bash 脚本输出通过管道传输到 Windows 上的文件

[英]How to pipe bash script output to a file on windows

I am running on Windows 7.我在 Windows 7 上运行。

I have a bash script which runs fine from a Windows command prompt using "C:\\Program Files\\Git\\git-cmd.exe" "C:\\path\\myBashScript.sh" 17.1 .我有一个 bash 脚本,它使用"C:\\Program Files\\Git\\git-cmd.exe" "C:\\path\\myBashScript.sh" 17.1从 Windows 命令提示符运行良好。 I can see it running in a new bash window, the output looks fine and it closes.我可以看到它在一个新的 bash 窗口中运行,输出看起来很好并且它关闭了。 What I want to do is capture the output in a file for further processing.我想要做的是捕获文件中的输出以供进一步处理。

I tried我试过

"C:\\Program Files\\Git\\git-cmd.exe" "C:\\path\\myBashScript.sh" 17.1 > C:\\out\\myBashScript.out.txt

but all I get in the output is the working folder, ie, C:\\path>但我在输出中得到的只是工作文件夹,即C:\\path>

Is this possible?这可能吗?

Thanks谢谢

"C:\\Program Files\\Git\\git-cmd.exe" is a frontend windows launcher. "C:\\Program Files\\Git\\git-cmd.exe" 是一个前端 Windows 启动器。 I'm surprised it takes any argument at all.我很惊讶它根本不需要任何争论。 You should run bash scripts using bash interpreter:您应该使用 bash 解释器运行 bash 脚本:

"C:\Program Files\Git\bin\bash.exe" "C:\path\myBashScript.sh"

PS: I'd advise to apply redirection inside the bash script rather than in windows commandline, they are better controlled there. PS:我建议在 bash 脚本中而不是在 Windows 命令行中应用重定向,它们在那里得到更好的控制。

You need to discriminate between the outputs generated within the shell script, and those generated by the command line execution.您需要区分 shell 脚本中生成的输出和命令行执行生成的输出。

To easily capture the output of the shell script, you may find it easier to do the redirection > to the capture file within the script.要轻松捕获 shell 脚本的输出,您可能会发现在脚本中执行重定向 > 到捕获文件更容易。

You didn't say what style of system you were on, and how it was set up (Cygwin, GfW; command line in cmd.exe, or bash; integrated or separated git commands (in the cmd.exe), etc).你没有说明你使用的是什么风格的系统,以及它是如何设置的(Cygwin、GfW;cmd.exe 或 bash 中的命令行;集成或分离的 git 命令(在 cmd.exe 中)等)。 I suspect that the inability to do a simple redirection of the command line is because of that system setup issue.我怀疑无法对命令行进行简单的重定向是因为系统设置问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM