Search code examples
bashbatch-filecygwindos

Output Cygwin/bash results to text file


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.txt file when executed from either the command line or the Scheduler.

This is the content of the batch file:

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

Solution

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

    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 stderr too to the file.