1

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

Sign up to request clarification or add additional context in comments.

Comments

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"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.