Как мне перенаправить вывод ношестей в текстовый файл?

StackOverflow https://stackoverflow.com/questions/9519717

  •  14-11-2019
  •  | 
  •  

Вопрос

Я пробовал "nosetests p1.py> text.txt", и он не работает.

Какой правильный способ трубовать этот консольный вывод?

Это было полезно?

Решение

Try:

nosetests -s p1.py > text.txt 2>&1

Last --obvious--tip: If you are not in the test file directory, add before the .py file.

Другие советы

I want to add more detail here.

On my version (v1.3.7) Nose is logging on stderr instead of the expected stdout. Why nose logs on stderr instead of stdout is beyond me. So the solution is to redirect the stderr stream to your file. The redirect character sends stdout by default. The --nocapture, -s flag is used to stop nose from capturing your own print statements.

$ nosetests -s -v test/ > stdout.log 2> stderr.log

One thing to note, is although stderr seems to be flushed on each output, stdout does not get flushed, so if you are tailing the stdout.log file, you will not see output until nose or the OS decides to flush. So if you think it's not working try exiting the test runner which will cause stdout to flush.

See this answer on redirecting linux streams.

parameter -s - Not capturing stdout

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top