stdout

In Go, how do I capture stdout of a function into a string?

▼魔方 西西 提交于 2020-01-26 12:47:09
问题 In Python, for example, I can do the following: realout = sys.stdout sys.stdout = StringIO.StringIO() some_function() # prints to stdout get captured in the StringIO object result = sys.stdout.getvalue() sys.stdout = realout Can you do this in Go? 回答1: I agree you should use the fmt.Fprint functions if you can manage it. However, if you don't control the code whose output you're capturing, you may not have that option. Mostafa's answer works, but if you want to do it without a temporary file

how to get the normal print statement execution when using stdout=subprocess.PIPE during subprocess call in python

好久不见. 提交于 2020-01-25 17:36:49
问题 I am starting a subprocess in python through this command: result = subprocess.Popen([sys.executable, "/subscript.py"] + parameter,stdout=subprocess.PIPE ) result.wait() out, err = result.communicate() for line in out.splitlines(): print line The problem that I am facing with this approach is that all the print statements in subscript.py are kind of buffered till the end and are printed on the terminal at the end of the execution. So if my subscript.py takes about 15 minutes in execution then

p.stdout.read() doesn't work in my Python 3 codes

隐身守侯 提交于 2020-01-24 21:48:45
问题 I try to create a sub-process using the subprocess module in MAC OS. Below is my code: import subprocess p = subprocess.Popen("app", stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True) p.stdin.write(bytes("3\n", "ascii")) p.stdin.write(bytes("4\n", "ascii")) print(p.stdout.read()) The source code of app is : #include <iostream> using namespace std; int main() { int x, y; cout << "input x: " << endl; cin >> x; cout << "input y: " << endl; cin >> y; cout <

How to write raw type / bytes to stdout?

风格不统一 提交于 2020-01-24 03:49:08
问题 I am struggling for quite some time with outputting a raw type to standard output. Here is what I tried and did not work the desired way: r <- as.raw(c(0x41, 0x00, 0x43)) # r = "A\0C" cat(rawToChar(r)) # displays warning and skips data after NULL (outputs "A") cat(r) # outputs "41 00 43" writeBin(r, stdout()) # error: can only write to binary connection I am looking for a way to get all three bytes / characters printed to stdout. 回答1: If you are using an operating system that has a 'cat' or

Is there a way to configure PuTTY or other terminal to flash the taskbar on next output to stdout?

冷暖自知 提交于 2020-01-23 05:22:20
问题 I'm specifically looking for a solution for PuTTY but also interested for other terminal emulators, like Gnome Terminal. My thought is it would be useful if I start a tar zxvf to be able to set a trigger on the terminal emulator, minimize it, and on next output to stdout/stderr I get a notification in the task bar that the command has finished. 回答1: This works for me: echo -e "\a" Then update your PuTTY session to use the Visual Bell, and set "Taskbar/caption indication on bell" to Flashing

How can I roll over Tomcat 5.5 stderr and stdout files when they get too large/big?

廉价感情. 提交于 2020-01-23 02:48:28
问题 I have been trying to figure out a way to take the Tomcat 5.5 stderr and stdout log files and roll them over when they get too large, but I have been unable to do so. Now, please understand this is NOT for web app logging. This is just the stdout and stderr logs that are automatically created by Tomcat. Again, they get too large, and I just need a method to roll them over when they get too large and/or on a time interval (i.e. every day, every hour). I tried using log4j, but that appears to

Simultaneous pipe to grep and redirect to stdout

随声附和 提交于 2020-01-22 20:50:10
问题 In Linux bash, I am trying to run a command and grep for an argument: command | grep However, I need to redirect the result of the commad to the stdout and simultaneously pipe it to grep (I need to see both the grep result and the command result in stdout). I googled a bit and tried some variations, such as: command | tee /dev/tty | grep But, no luck. I don't want to use sth like command command | grep as it is ugly :) Thanks, 回答1: Try command | tee >(grep whatever) Note that there's no space

Capturing output from WshShell.Exec using Windows Script Host

安稳与你 提交于 2020-01-19 05:50:06
问题 I wrote the following two functions, and call the second ("callAndWait") from JavaScript running inside Windows Script Host. My overall intent is to call one command line program from another. That is, I'm running the initial scripting using cscript, and then trying to run something else (Ant) from that script. function readAllFromAny(oExec) { if (!oExec.StdOut.AtEndOfStream) return oExec.StdOut.ReadLine(); if (!oExec.StdErr.AtEndOfStream) return "STDERR: " + oExec.StdErr.ReadLine(); return

python print function in real time

回眸只為那壹抹淺笑 提交于 2020-01-19 05:41:07
问题 I recently switched OS and am using a newer Python (2.7). On my old system, I used to be able to print instantaneously. For instance, suppose I had a computationally intense for loop: for i in range(10): huge calculation print i then as the code completed each iteration, it would print i However, on my current system, python seems to cache the stdout so that the terminal is blank for several minutes, after which it prints: 1 2 3 in short succession. Then, after a few more minutes, it prints:

How to write to StdOut in Windows and FASM?

99封情书 提交于 2020-01-17 01:11:08
问题 The question is pretty simple, yet I can't seem to find how to do it: how do I write to StdOut in Windows/FASM? There does not seem to be any documentation online. Ideas? 回答1: There are a few options... 1) Use the WinAPI. This is either WriteConsole OR by using CreateFile with the filename as CON and then using WriteFile 2) Using msvcrt, and printf as you would in a c program. 来源: https://stackoverflow.com/questions/7263097/how-to-write-to-stdout-in-windows-and-fasm