将 Cygwin/bash 结果输出到文本文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8157779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 01:04:39  来源:igfitidea点击:

Output Cygwin/bash results to text file

bashbatch-filecygwindos

提问by Michael Gorham

I'm writing a script that will run from the Task Scheduler. It's not executing correctly from the Scheduler, but will execute correctly from the command line. (Possibly a permissions issue?) I wanted to redirect the output to a text file, but I'm getting an empty results.txtfile when executed from either the command line or the Scheduler.

我正在编写一个将从任务计划程序运行的脚本。它没有从调度程序正确执行,但会从命令行正确执行。(可能是权限问题?)我想将输出重定向到文本文件,但是results.txt从命令行或调度程序执行时得到一个空文件。

This is the content of the batch file:

这是批处理文件的内容:

D:
chdir D:\scripts
C:\cygwin\bin\bash --login -i D:\scripts\myscript.sh > results.txt

回答by palacsint

Maybe your script writes to the standard error (stderr). Try changing

也许您的脚本写入标准错误 ( stderr)。尝试改变

C:\cygwin\bin\bash --login -i D:\scripts\myscript.sh > results.txt

to

C:\cygwin\bin\bash --login -i D:\scripts\myscript.sh > results.txt  2>&1

It's redirects stderrtoo to the file.

它也重定向stderr到文件。

回答by Peter van der Heijden

Try a UNIX style file path:

尝试使用 UNIX 样式的文件路径:

C:\cygwin\bin\bash --login -i /cygdrive/d/scripts/myscript.sh > results.txt