stdout

What is an appropriate way to programmatically exit an application?

≯℡__Kan透↙ 提交于 2019-12-04 05:49:19
问题 I am evaluating user inputs as commands for my application. If the user presses Q , or q , and then hits enter, the application quits and execution terminates. Is there a proper context, or best practices on how to do that? I do not have any resources to release, or anything like that. Should I just use System.exit(0); ? Is there a recommended way to do that? As my first approach I do something like this: while (true){ try{ BufferedReader br = new BufferedReader(new InputStreamReader(System

Redirecting stdout from a secondary thread (multithreading with a function instead of class?)

允我心安 提交于 2019-12-04 05:48:41
问题 I am trying to get my stdout displayed on a QTextEdit made via Qt Designer (PyQt5). Actually I made it work yet it doesn't show the info at the same time it was made. Instead it waits for the process to completely end and only then it shows all the information at once. I understand that this should be solved via threading. Also since the QTextEdit (itself) is a GUI element i need a different approach. I found the answer I was looking for here: This question is referenced to: Redirecting

Duplicate stdout and stderr from fork process to files

烂漫一生 提交于 2019-12-04 05:44:50
问题 I need to duplicate stdout and stderr of a child proccess to multiple files. I understand that i can use tee() , but I haven't found examples for that. Now, it's only to print all to stdout and stderr. How to do it? pid_t childId = fork(); switch(childId){ case -1: perror("fork() error!\n"); return; case 0: mysignal(SIGTTOU, SIG_DFL); mysignal(SIGTTIN, SIG_DFL); mysignal(SIGCHLD, SIG_DFL); if(!background) tcsetpgrp(cterm, getpid()); setpgid(0, 0); if (isWriter) close(pipefd[0]); if (isReader!

Stop a function from writing to stdout

主宰稳场 提交于 2019-12-04 05:27:34
问题 I have this line in my code: writer = cv.CreateVideoWriter('video.avi', cv.CV_FOURCC('X','V','I','D'), 30 ,(480,800), 1) Which outputs to console this: Output #0, avi, to 'video.avi': Stream #0:0: Video: mpeg4, yuv420p, 480x800, q=2-31, 24576 kb/s, 90k tbn, 30 tbc I want to stop it from printing anything to stdout, but keep the possibility to output by myself something further in the code. How can I achieve this? I tried this, but it didn't worked. class NullStream: def write(self, text):

Printing to STDOUT and log file while removing ANSI color codes

无人久伴 提交于 2019-12-04 05:03:35
I have the following functions for colorizing my screen messages: def error(string): return '\033[31;1m' + string + '\033[0m' def standout(string): return '\033[34;1m' + string + '\033[0m' I use them as follows: print error('There was a problem with the program') print "This is normal " + standout("and this stands out") I want to log the output to a file (in addition to STDOUT) WITHOUT the ANSI color codes, hopefully without having to add a second "logging" line to each print statement. The reason is that if you simply python program.py > out then the file out will have the ANSI color codes,

How can I do an atomic write to stdout in python?

强颜欢笑 提交于 2019-12-04 04:51:07
I've read in some sources that the print command is not thread-safe and the workaround is to use sys.stdout.write command instead, but still it doesn't work for me and the writing to the STDOUT isn't atomic. Here's a short example (called this file parallelExperiment.py): import os import sys from multiprocessing import Pool def output(msg): msg = '%s%s' % (msg, os.linesep) sys.stdout.write(msg) def func(input): output(u'pid:%d got input \"%s\"' % (os.getpid(), str(input))) def executeFunctionInParallel(funcName, inputsList, maxParallelism): output(u'Executing function %s on input of size %d

How to check if stdout has been redirected to NUL on Windows (a.k.a. /dev/null on Linux)?

我们两清 提交于 2019-12-04 04:44:04
问题 How can I check if my program's stdout has been redirected to NUL ? That way I can avoid outputting data since it's pointless. I mainly need this for Windows, but if you have a Linux solution, it might be helpful for others in the future, so feel free to post that as well. 回答1: There are probably other ways to do this (and it wouldn't be a surprise if there turns out to be a proper function for it I've overlooked), but here's one way: enum { Output_Console, Output_File, Output_NUL, }; bool

How to capture the standard output/error of a Process?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-04 04:38:30
问题 How does one capture the standard output/error of a process started by a Process.Start() to a string ? 回答1: By redirecting it and reading the stream. 回答2: To solve the deadlock problems use this approach: ProcessStartInfo hanging on "WaitForExit"? Why? Works well in my code... 回答3: Sample code is below: ProcessStartInfo psi = new ProcessStartInfo(); psi.CreateNoWindow = false; psi.UseShellExecute = false; psi.FileName = "C:\\my.exe"; psi.WindowStyle = ProcessWindowStyle.Hidden; psi

Where is stdout for a Mac App?

谁说我不能喝 提交于 2019-12-04 03:57:25
It used to be that stdout went to the console log, displayed by Console.app. I've been having some problems with a firefox plugin (see other questions, sorry about the spam...) and I was trying to use printfs to at least see if I was STARTING my plugin. I just noticed today that my console log hasn't been updated since January 6. (Yes, I've been using the machine for the past month.) Now, I'm not the only program that uses the console log, so all those messages must be going SOMEWHERE else. Does anyone know where? The problem was that syslogd was broken. It's fixed now. printf should be going

Read another process' stdout in C++

不问归期 提交于 2019-12-04 03:40:41
In Windows, is there a way to launch a process in C++ and then read what it spat out into stdout when it's done? The process must be run using elevated privileges (on Vista or later) if necessary. I'm currently using ShellExecuteEx() to launch the process and running a while-loop until GetExitCodeProcess() no longer returns STILL_ACTIVE via the lpExitCode parameter (with a WaitForSingleObject() call doing a 100 msec wait during each iteration). There's no easy way to do this. Calling ShellExecuteEx() with the runas verb sends an RPC message to the AppInfo NT Service witch then run the