stdout

Is there a way to catch the stderr and stdout in Visual Studio?

[亡魂溺海] 提交于 2019-11-30 16:33:18
问题 Is there a way to catch the stdout and stderr in Visual Studio? For example, when I use cout <<"Hello world!"<< endl; A black window appears and disappears. It's so fast that I can't see it. There is a output section in the IDE but it only allow me to choose display output from build and something else but without the choice of stdout. A cheating solution maybe calling system("pause"); but it doesn't sound right. I searched in the option but I can't find an item. Anyone has any idea? Thanks.

Get live stdout from gevent-subprocess?

老子叫甜甜 提交于 2019-11-30 15:30:34
I'm trying to get the stdout of a process via POPEN as soon as it's there. With gevent 1.0 readline() and read() still block process and wait for process to finish. Any clues? And yes, I searched high and low for a simple solution. It has to be possible without threading, right? import gevent from gevent.subprocess import Popen, PIPE def cron(): while True: print("cron") gevent.sleep(0.5) g = gevent.spawn(cron) def subp(): sub = Popen('sleep 1; ping www.google.com -c 2; sleep 5; uname', stdout=PIPE, shell=True) while True: s = sub.stdout.readline() if s == "": break else: print s.strip() g

How to redirect the output of system() to a file?

空扰寡人 提交于 2019-11-30 14:19:10
In this C program #include <stdio.h> #include <fcntl.h> int main() { int file = open("Result", O_CREAT|O_WRONLY, S_IRWXU); dup2(stdout, file); system("ls -l"); return 0; } I'm trying to redirect the output of system() to a file, for that i have used dup2 but it is not working. What's wrong with this code ? and, please tell me if there is any better way to do this ? (without using > at the terminal ) stdout is a FILE * pointer of the standard output stream. dup2 expects file descriptor, also you've messed up the parameters order. Use dup2(file, 1); instead. On the better-way-to-do-this part.

python: change sys.stdout print to custom print function

孤者浪人 提交于 2019-11-30 14:17:05
问题 Im trying to understand how to create a custom print function. (using python 2.7) import sys class CustomPrint(): def __init__(self): self.old_stdout=sys.stdout #save stdout def write(self, text): sys.stdout = self.old_stdout #restore normal stdout and print print 'custom Print--->' + text sys.stdout= self # make stdout use CustomPrint on next 'print' # this is the line that trigers the problem # how to avoid this?? myPrint = CustomPrint() sys.stdout = myPrint print 'why you make 2 lines??...

Fork child process with timeout and capture output

冷暖自知 提交于 2019-11-30 14:01:50
问题 Say I have a function like below, how do I capture the output of the Process.spawn call? I should also be able to kill the process if it takes longer than a specified timeout. Note that the function must also be cross-platform (Windows/Linux). def execute_with_timeout!(command) begin pid = Process.spawn(command) # How do I capture output of this process? status = Timeout::timeout(5) { Process.wait(pid) } rescue Timeout::Error Process.kill('KILL', pid) end end Thanks. 回答1: You can use IO.pipe

launch app, capture stdout and stderr in c++

不想你离开。 提交于 2019-11-30 13:55:40
How do I launch an app and capture the output via stdout and maybe stderr? I am writing an automated build system and I need to capture the output to analyze. I'd like to update the svn repo and grab the revision number so I can move the files in autobuild/revNumber/ if successful. I also would like to build using make and upload the compile text to my server for everyone to see the warnings and errors on a failed build. I can't find the system() function, but I found the CreateProcess() function on MSDN. I am able to launch what I need but I have no idea how to capture the stderr and stdout.

Linux/Perl: Additional output buffers other than STDOUT and STDERR?

耗尽温柔 提交于 2019-11-30 13:43:20
Out of curiosity, is it possible to create, instantiate, or otherwise access additional output buffers besides STDOUT and STDERR from within a Perl script? The use case would be additional outputs to pipe in to files or other commands, eg ./doublerainbow.pl 3>full_on.txt 4>all_the_way!.txt mob Absolutely. The open command with the >&= mode allows you to open filehandles on arbitrary file descriptors. # perl 4fd.pl > file1 2> file2 3> file3 4> file4 5< file5 open STDFOO, '>&=3'; open STDBAR, '>&=4'; open STDBAZ, '<&=5'; # works for input handles, too print STDOUT "hello\n"; print STDERR "world

Fork child process with timeout and capture output

落爺英雄遲暮 提交于 2019-11-30 13:13:12
Say I have a function like below, how do I capture the output of the Process.spawn call? I should also be able to kill the process if it takes longer than a specified timeout. Note that the function must also be cross-platform (Windows/Linux). def execute_with_timeout!(command) begin pid = Process.spawn(command) # How do I capture output of this process? status = Timeout::timeout(5) { Process.wait(pid) } rescue Timeout::Error Process.kill('KILL', pid) end end Thanks. You can use IO.pipe and tell Process.spawn to use the redirected output without the need of external gem. Of course, only

How can I print to console while the program is running in python? [duplicate]

吃可爱长大的小学妹 提交于 2019-11-30 13:10:40
Possible Duplicate: How to flush output of Python print? I have have an algorithm that I'm running that takes a while, so I want to keep track of how far it's through, by printing to the console. So something like: import sys def myMethod(): i = 0 while (i<1000000): i = i+1 output_str = str(i) + "\n" sys.stdout.write(output_str) # same as print sys.stdout.flush() myMethod() How can I have this print while it's running, rather than at the end? Edit, Solution: - Posted amended code. This code works fine when you run it in the linux terminal using python filename.py But when I run it in Wing 101

How can I redirect R warning messages to STDOUT?

故事扮演 提交于 2019-11-30 12:50:29
I'm using a grid engine to run R scripts. The STDERR is taken seriously under this setup, so I would like to keep it clean and have only real/serious/fatal errors printed to STDERR. The problem is my R script generate various STDERR messages which are not really serious warnings... for example, scan seems to print to STDERR the number of items it read. Can I redirect (from within R) STDERR to STDOUT? Look at the help page for sink() : ‘sink’ diverts R output to a connection. If ‘file’ is a character string, a file connection with that name will be established for the duration of the diversion.