0

How do I output batch file output to console and file?

I tried using > like this but it only outputs to file.

Powershell.exe -ExecutionPolicy ByPass -File %psFile% %2 %3 %4 %5 %6 > LOG.txt
Mofi
  • 46,139
  • 17
  • 80
  • 143
Cataster
  • 3,081
  • 5
  • 32
  • 79
  • 1
    I tried tee. It's not recognizable – Cataster May 27 '19 at 01:23
  • Try `set "psFile=.\main.ps1"` + `Powershell.exe -ExecutionPolicy ByPass -Command "&{%psFile% %2 %3 %4 %5 %6 | Tee-Object -FilePath log.txt}"`. Refer to [Tee-Object](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.utility/tee-object?view=powershell-3.0). – michael_heath May 27 '19 at 03:14
  • Why are you complaining about `cmd.exe`, which you're using to run a [tag:powershell] script, not recognizing a `powershell.exe` command? If you're running a powershell script, run it in `powershell.exe` or run a powershell command instead of a file, and use the `Tee-Object` cmdlet. – Compo May 27 '19 at 03:24
  • @Compo well I have to use batch file to bypass the ps script through the server security, so I'm hoping to redirect output to both console and file from the batch file line I have in my post – Cataster May 27 '19 at 04:16
  • @michael_heath hey so I tried it out and it's not outputting everything. Can u see this thread? https://stackoverflow.com/questions/56333784/why-is-most-of-the-output-not-being-redirected-to-the-file – Cataster May 28 '19 at 02:03

0 Answers0