stderr

Python logging split between stdout and stderr [duplicate]

怎甘沉沦 提交于 2019-12-29 03:17:30
问题 This question already has answers here : How can INFO and DEBUG logging message be sent to stdout and higher level message to stderr (7 answers) Closed 6 years ago . Is it possible to have python logging messages which are INFO or DEBUG to go to stdout and WARNING or greater to go to stderr? 回答1: This seems to do what I want: #!/usr/bin/python import sys import logging class InfoFilter(logging.Filter): def filter(self, rec): return rec.levelno in (logging.DEBUG, logging.INFO) logger = logging

Python subprocess with /usr/bin/time: How can I capture timing information, but ignore all other output?

僤鯓⒐⒋嵵緔 提交于 2019-12-28 14:07:12
问题 I am trying to measure the execution time in seconds of an executable program invoked via subprocess. I do not want the output of the executable (either stderr or stdout) to be emitted. I have tried the timeit and resource libraries, but neither accurately captures the time of the process, seemingly it only captures the timing in the Python worker thread. This attempt below will lose the timing info b/c of the stderr redirect. However, w/o the stderr redirect, the command 'f_cmd' stderr

How does Qt5 redirect qDebug() statements to the Qt Creator 2.6 console

拟墨画扇 提交于 2019-12-28 12:29:47
问题 After searching around for a reason that qDebug() statements work fine with Qt's standard message handler but fail when I switch to my own, I'm appealing here to see if anyone else has any experience with the problem. Things I know about / have tried, that do nothing... 1) CONFIG += console 2) DEFINES -= QT_NO_WARNING_OUTPUT QT_NO_DEBUG_OUTPUT 3) ::fprintf(stderr, "ERROR\n"); ::fflush(stderr); 4) ::fprintf(stdout, "OUTPUT\n"); ::fflush(stdout); 5) std::cerr << "CERROR" << std::endl; std::cerr

Python multiprocessing: How can I RELIABLY redirect stdout from a child process?

女生的网名这么多〃 提交于 2019-12-28 11:53:04
问题 NB. I have seen Log output of multiprocessing.Process - unfortunately, it doesn't answer this question. I am creating a child process (on windows) via multiprocessing. I want all of the child process's stdout and stderr output to be redirected to a log file, rather than appearing at the console. The only suggestion I have seen is for the child process to set sys.stdout to a file. However, this does not effectively redirect all stdout output, due to the behaviour of stdout redirection on

How do I redirect stderr and stdout to file for a Ruby script?

帅比萌擦擦* 提交于 2019-12-28 02:50:06
问题 How do I redirect stderr and stdout to file for a Ruby script? 回答1: From within a Ruby script , you can redirect stdout and stderr with the IO#reopen method. # a.rb $stdout.reopen("out.txt", "w") $stderr.reopen("err.txt", "w") puts 'normal output' warn 'something to stderr' $ ls a.rb $ ruby a.rb $ ls a.rb err.txt out.txt $ cat err.txt something to stderr $ cat out.txt normal output 回答2: Note: reopening of the standard streams to /dev/null is a good old method of helping a process to become a

How to replicate tee behavior in Python when using subprocess?

喜欢而已 提交于 2019-12-28 01:51:51
问题 I'm looking for a Python solution that will allow me to save the output of a command in a file without hiding it from the console. FYI: I'm asking about tee (as the Unix command line utility) and not the function with the same name from Python intertools module. Details Python solution (not calling tee , it is not available under Windows) I do not need to provide any input to stdin for called process I have no control over the called program. All I know is that it will output something to

linux环境下nohup的执行jar

寵の児 提交于 2019-12-27 02:44:31
java -jar XXX.jar & 命令结尾没有 “&” ,则变成 “java -jar XXX.jar ” ,表示在当前ssh窗口,可按CTRL + C打断程序运行,或者直接关闭窗口,则程序直接退出 命令结尾添加 “&” ,则变成 “java -jar XXX.jar &” ,表示在当窗口关闭时,程序才会中止运行。&代表让该命令在后台执行。 nohup java -jar XXX.jar > Log.log & 或者 nohup java -jar XXX.jar >> Log.log & 命令 “nohup java -jar XXX.jar &” 部分,表示不挂断运行命令,当账户退出或终端关闭时,程序仍然运行。注意,该作业的所有输出被重定向到nohup.out的文件中。 命令 “nohup java -jar XXX.jar > Log.log &” 部分,表示不挂断运行命令,当账户退出或终端关闭时,程序仍然运行,并且该作业的所有输出被重定向到Log.log的文件中。“ > Log.log ” 该命令就是指定日志输出的文件。 ">>"表示将输出以追加的方式重定向到Log.log中。 nohup java -jar XXX.jar > Log.log 2>&1 & 或者 nohup java -jar XXX.jar >> Log.log 2>&1 & 或者 nohup

记一次传递文件句柄引发的血案

匆匆过客 提交于 2019-12-26 17:55:06
apue 上讲 Solaris 系统是可以在进程间通过 STREAMS 管道传递文件句柄的。 书上讲道:“在技术上,发送进程实际上向接收进程传送一个指向一打开文件表项的指针,该指针被分配存放在接收进程的第一个可用描述符项中。” 个人非常感兴趣,就写下了下面的两个程序来验证 STREAMS 管道是否支持发送接收文件描述符,且发送方与接收方的描述符是否可能不相同。 spipe_server.c 1 #define MAXLINE 128 2 3 int get_temp_fd () 4 { 5 char fname[128] = "/tmp/outXXXXXX"; 6 int fd = mkstemp (fname); 7 printf ("create temp file %s with fd %d\n", fname, fd); 8 return fd; 9 } 10 11 int main (int argc, char *argv[]) 12 { 13 if (argc < 2) { 14 printf ("usage: spipe_server <spipe_client>\n"); 15 return 0; 16 } 17 18 int n; 19 int fd[2], fd_to_send, fd_to_recv; 20 if (pipe (fd) < 0) { 21

Redirecting stdout, stderror to file while stderr still prints to screen

蹲街弑〆低调 提交于 2019-12-25 18:23:25
问题 I would like stdout and stderr to be redirected to the same file, while stderr still writes to the screen. What's the most pythonic way to do this? 回答1: I'm assuming you want to redirect the current script's stdout and stderr, not some subprocess you're running. This doesn't sound like a very Pythonic thing to do in the first place, but if you need to, the Pythonic solution would be: Redirect stdout to a file. Redirect stderr to a custom file-like object that writes to the file and also

BASH: different colour for text entered by user

五迷三道 提交于 2019-12-25 12:38:06
问题 I've been tidying up my BASH prompt. Currently it looks like this: Here is the code: # NOTE: OSX uses .bashprofile http://superuser.com/questions/244964/mac-os-x-bashrc-not-working # http://mywiki.wooledge.org/BashFAQ/037 bold=$( tput bold || tput md ) black=$( tput setaf 0 ) red=$( tput setaf 1 ) green=$( tput setaf 2 ) blue=$( tput setaf 4 ) white=$( tput setaf 7 || tput AF 7 ) RESET=$( tput sgr0 ) # https://github.com/sickill/stderred export DYLD_INSERT_LIBRARIES="/usr/lib/libstderred