This duplicated filedescriptor is stored in StreamCapture.dup_fd, and StreamCapture also uses os.dup to duplicate the original filedescriptor to be able StreamCapture works by essentially using os.dup2 to send stream.fileno() to a os.pipe().Ī separate thread is used to listen to that os.pipe and send the outputs to the destination This will even capture the outputs of spawned shell commands. DocumentationĬlass StreamCapture(stream, writer, echo=True, monkeypatch=None) is able to capture,Īt the operating system level, the data being written to the given stream.Ī typical use is to capture all outputs to sys.stdout and sys.stderrĪnd log them to a file. system ( 'echo Hello from the shell' ) print ( "More capturing" ) print ( "This also does not get saved to the log file" )Īfter execution, this will create a file logfile.txt in the current directory, containing fileno (), b "Hello, captured world! \n " ) os. stdout, open ( 'logfile.txt', 'wb' )): os. Pip install streamcapture Example usage import streamcapture, sys, os print ( "This does not get saved to the log file" ) with streamcapture. Streamcapture: capture the outputs of Python streams, such as sys.stdout and sys.stderr Author: Sébastien Loisel Installation
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |