Welcome to PhoneASK, where you can ask questions and receive answers from other members of the community.

Discover source of stdout output

asked 9 days ago by Ingo Kegel

I'm using a third party lib that is printing \n a couple of hundred times to stdout - it appears to be a bug in their logging.

What is the best approach to discover what line of code is producing this output (I'm hoping it's python and not an external library)?

Some ideas:

  • How can I change the display of the \n character to something recognizable like A so that if I step through with a debugger, I can see when the output occurs?

  • Can I monkey-patch a low level function to cause some output or a debug-break everytime characters are sent to std-out?

Your answer

1 Answers

answered 8 days ago by C. A. McCann

You could try to overtake stdout:

class StdoutFilter:
    def __init__(self, realStdout):
        self.realStdout = realStdout

    def write(self, text):
        if text == '\n':   # or some more complicated condition
            raise Exception("Newline alert!")


import sys
sys.stdout = StdoutFilter(sys.stdout)

# import the 3rd party library and use it

In this filter class you can add a counter and raise the exception only after more than N subsequent newlines were printed. The stack trace of the exception will reveal the source of the malicious print.

Or you can put a break point there, or change the \n to something else.

Related Questions

I am trying to build a spec for this statement. It is easy with 'puts' print '#{@file}' doesn't exist: Create Empty File (y/n)?
I have a simple function like: nth :: Integer -> Integer And I try to print it's result as follows: main = do n <- getLine result <- nth (read n :: Integer) print result The following error
Hi I have seen there are already many questions on this issue however none of them seems to answer my query . As per below link i even tried winpexpect as i am using windows , however it dosent seems
At the moment I am starting a batch file from my C# program with: System.Diagnostics.Process.Start(@DoSomeStuff.bat); What I would like to be able to do is redirect the output (stdout and stderr) o
Is possible to output to stdout a simple Haskell one-liner like main = print Hello World directly from Bash? Something ala php -r 'echo Hello World\n;' I poked around in the ghc options but I did
I am using the ant (1.8.2) exec task to start a child process. I need the output of the child process to be shown as part of the normal ant console output, but also be captured in a file.
I'm running an application in a Glassfish server from Eclipse using verbose output. Therefore, all the logging gets written into the console. The thing is that when an exception occurs, I can see the
How does one declare stdin, stout, and stderr (preferably the C versions) in LLVM? I am trying to use some stdio functions in a toy language I am creating. One such function was fgets: char * fgets (
I want to redirect all console output to my own GUI console, including all calls to C write functions. Things I've tried: Creating a new stream class, but stdio.stdout is a file and you can't assign
I am attempting to spawn a subprocess from Golang. The goal is to read and process the input line-by-line. Here is what I am trying to get working: func readStuff(scanner *bufio.Scanner) { for scanner
I am using boiler plate code of mean.io and starting the server with command node server.js How do I log stdout and stderr of my express application? Following is my server.js 'use strict'; /** * Mod
Because I'm currently setting up a new server for use, I've been using a lot of command-line programs like curl and wget, and I've noticed that they do something interesting. When run in the Terminal,
I am trying to do something like: patch <( zcat data.201301.gz ) patch_file.diff -o /dev/stdout result I am getting is: File /dev/fd/63 is not a regular file -- refusing to patch 4504 out of 4504
I got some code that prints to stdout, in pseudo code it looks like int main(){ //allocate data while(conditional){ char *string = makedata(); fprintf(stdout,%s,string); } //cleanup } This works fi
I am writing a DLL which may run in the context of a service and may be loaded into a standard win32 process. How can I detect whether it is running in the context of a service or in the context of a
I have seen references online that state that Scheduled Tasks in Windows are stored in %SystemRoot%\Tasks (usually C:\Windows\Tasks). However on my Windows 7 system, I observe that while that folder e
Is there an fast and easy way to discover the precedence and associativity a function in GHCI? I've found that one straightforward method is to bruteforce combining one operator with another other unt
I am trying to build an app for iOS that can connect to computers running macOS or windows, and control a few stuff on those computers. Another application will be installed on those computers so that
I have a large sequence of tuples on disk in the form (t1, k1) (t2, k2) ... (tn, kn) ti is a monotonically increasing timestamp and ki is a key (assume a fixed length string if needed). Neither ti nor
I need to write a PHP script that will output data from a PostgreSQL database that I do not know the structure of. What query will return the names of all tables in a database? And what query will lis
public final static InputStream in = null; public final static PrintStream out = null; public final static PrintStream err = null; But as we very well know, these streams are connected to the console
This question already has an answer here: Setting the correct encoding when piping stdout in Python 9 answers I'm having a problem regarding Unicode in Python. I can print the output fine in a
I want my program to display the unix windmill while processing. There's a for loop and in every iteration theres a printf function: printf(Fetching articles (%c)\r,q); q is one of the characters i
Possible Duplicate: Writing to stdin and reading from stdout (UNIX/LINUX/C Programming) I have a simple question regarding stdio of linux system. what happens if a program writes to stdin? or reads
I am calling a function in a java library from jython which prints to stdout. I would like to suppress this output from the jython script. I attempt the python idiom replacing sys.stdout with a file l
You can split a pipe using the tee command under linux as follows printf line1\nline2\nline3\n | tee >(wc -l ) | (awk '{print this is awk: $0}') which yields the output this is awk: line1 this
I'm working on a simple shell, but right now I am just trying to understand redirection. I'm just hard coding an ls command and trying to write it to a file for now. Currently, the ls runs, and the ou
I am trying to write a python script to automate the process of checking for SSL renegotiation through openSSL and output the results to a file. I have run into 2 problems. My first problem is that th
I would like for my app (a single SKU) to provide different initial conditions (e.g. starting in-game currency) depending on if it was installed for free or if the user paid to install it. The price w
I need to discover local computers running my windows WCF service, so I can talk to them. Right now you have to enter manually the ipaddress:port combination, but I would like to have a (web?) appli
I have a list of 10,000 company websites and am trying to discover their blog feeds if they have one (any and all rss versions). I don't want to crawl them if i don't have to, so are there any tools,
I follow Bluetooth Low Energy guide, and try to test discovery feature on Samsung Galaxy Note 3 and Samsung Galaxy S3. But they can not find together via my application. Therefore, I try to download n
Possible Duplicate: How to get date of last Friday from specified date? Using java.util.Calendar (or any other library), is there a way i can find out what the Date of what Month of what Year was F
If I were to receive a patch file generated with something like git diff rev^ rev or even git show -p rev, how can I discover which commits are being diffed? I'm not positive this use case is even rel
I am working on a Bluetooth LE application for iOS. I am using the Core Bluetooth framework within iOS to handle all communications. Question & Description: When I use a single tag, despite numer
I am new to Rails, and I am finding it extremely opaque. I have a copy of the latest Agile Web Development with Rails, but my worry is that without this book I would be completely lost. For example, f
Following up on a previous question ( subprocess: PyDev console vs. cmd.exe ), is there a way to change where PyDev sends stdout--namely to a tty terminal? I've come across several instances where not
I'm trying to debug some Capybara integration tests and running into an unexpected issue. When I set a breakpoint inside a Capybara test, I can inspect variables, but i can not call puts or $stdout.pu
I would like to write a simple script (A) that executes an external script (B) A should communicate with B by writing to its stdin and reading its stdout B should read its stdin and print it all th
I am using a third-party command line tool which writes its output to the console, but, unfortunately, does not write when it detects stdout is redirected. I need to write a c# application that captur
I am looking for a Python module that would add ANSI support under Windows. This means that after importing the module, if you output ANSI escaped strings, they will appear accordingly.
I have a simple Win32 GUI app which has an edit control in the main window. If I write: printf(Hello world!\n); I would like the text to appear in that control instead of the console. How to? Updat
I pass an executable on the command-line to my python script. I do some calculations and then I'd like to send the result of these calculations on STDIN to the executable. When it has finished I would
I Steven's UNIX Network Programming, he mentions redirecting stdin, stdout and stderr which is needed when setting up a daemon. He does with the following C code /* redirect stdin, stdout, and stderr
I want to paste the output of my Python script into a spreadsheet. For this to work, the output should use hard tabs, and not spaces, to separate fields. How to I convince Python that tabs is what I w
Hi I am running a bash script that creates a log file for the execution of the command I use the following Command1 >> log_file Command2 >> log_file This only sends the standard output an
I have a process which chats a lot to stderr, and I want to log that stuff to a file. foo 2> /tmp/foo.log Actually I'm launching it with python subprocess.Popen, but it may as well be from the sh
In a R session, I source a simple r script whose content is: x = c(1,2) x as source('my.r') I wonder why running it in the R session doesn't show any output? (I find that I can use print() to show t
Can stdout file descriptor differ from 1 (STDOUT_FILENO) assuming stdout need not be a modifiable lvalue? For example, can freopen(/dev/null, w, stdout) change fileno(stdout) result?
I am outputting to stdout. How can I redirect that to a new file through code? While we run the program we can redirect like ./sample > test.txt. How can I do this when executing the sample program