J
J
JZorkiy2020-05-02 21:46:24
PowerShell
JZorkiy, 2020-05-02 21:46:24

PowerShell. How to redirect error output to both file and terminal at the same time?

When compiling, you need to send the standard error output to the "error.txt" file, BUT , while the terminal should also have the same output:
g++ test.cpp -o test 2>> error.txt

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
MaxKozlov, 2020-05-02
@JZorkiy

It's the mistakes? then the easiest way is to a file, and then read it,
and if everything is in a row, then

g++ test.cpp -o test 2>&1 | Tee-Object -Filepath error.txt

Found another option
invoke-command { 'txt1'; write-error 'err'; 'txt2' } -ErrorVariable e
#пример вызова внешней команды
invoke-command { python 1.py 2>&1 } -ErrorVariable e
$e | Out-File error.txt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question