stdout vs console.write in c#

In languages like C and C++, there is a global variable with the name stdout, which is a pointer to the standard output stream. Thus, stdout has become a commonly used abbreviation for “standard output stream” even outside the context of the C language. Now, what does C# do? Let’s have a look at the … Read more

Get output from a Paramiko SSH exec_command continuously

A minimal and complete working example of how to use this answer (tested in Python 3.6.1) # run.py from paramiko import SSHClient ssh = SSHClient() ssh.load_system_host_keys() ssh.connect(‘…’) print(‘started…’) stdin, stdout, stderr = ssh.exec_command(‘python -m example’, get_pty=True) for line in iter(stdout.readline, “”): print(line, end=””) print(‘finished.’) and # example.py, at the server import time for x in … Read more

Is there a way to redirect stdout/stderr to a string?

Yes, you can redirect it to an std::stringstream: std::stringstream buffer; std::streambuf * old = std::cout.rdbuf(buffer.rdbuf()); std::cout << “Bla” << std::endl; std::string text = buffer.str(); // text will now contain “Bla\n” You can use a simple guard class to make sure the buffer is always reset: struct cout_redirect { cout_redirect( std::streambuf * new_buffer ) : old( … Read more

What’s the difference between stdout and STDOUT_FILENO?

stdout is a FILE* pointer giving the standard output stream. So obviously fprintf(stdout, “x=%d\n”, x); has the same behavior as printf(“x=%d\n”, x);; you use stdout for <stdio.h> functions such as fprintf(), fputs() etc.. STDOUT_FILENO is an integer file descriptor (actually, the integer 1). You might use it for write syscall. The relation between the two … Read more

Getting realtime output from ffmpeg to be used in progress bar (PyQt4, stdout)

In this specific case for capturing ffmpeg’s status output (which goes to STDERR), this SO question solved it for me: FFMPEG and Pythons subprocess The trick is to add universal_newlines=True to the subprocess.Popen() call, because ffmpeg’s output is in fact unbuffered but comes with newline-characters. cmd = “ffmpeg -i in.mp4 -y out.avi” process = subprocess.Popen(cmd, … Read more

Redirect stdout to a string in Java

Yes – you can use a ByteArrayOutputStream: ByteArrayOutputStream baos = new ByteArrayOutputStream(); System.setOut(new PrintStream(baos)); Then you can get the string with baos.toString(). To specify encoding (and not rely on the one defined by the platform), use the PrintStream(stream, autoFlush, encoding) constructor, and baos.toString(encoding) If you want to revert back to the original stream, use: System.setOut(new … Read more

tech