0

I have a script which when it runs, prints out lines to the terminal (with errors). I would like to redirect this output into files.

I read that I should add this line in my PS1 script: ".\myscript.ps1 *> &1 > outfile.log" but it doesn't work because of ampersand character is not allowed.

2

2 Answers 2

2

You don't need space symbol before ampersand.

.\myscript.ps1 *>&1 will redirect all output streams to the stream number 1

.\myscript.ps1 *>outfile.log will redirect all output streams to the file

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_redirection?view=powershell-6

0

If you just want to put your lines into another file from a terminal I would try this: ./myscript.ps1 2>outfile.log "./" activates the script "2>" takes the stderr stream into (in this case) the outfile.log But I am not sure what you are supposed to do. Maybe if you could post your code or your task here that would be great.

if you want both streams in one outlog, I would do it like that "2>&1"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.