stderr

What are the conventions for stdout/stderr messages?

丶灬走出姿态 提交于 2019-12-10 21:54:11
问题 I have an app that will fprintf both help and error messages to stderr . Should I send messages to stdout if I am exiting with status EXIT_SUCCESS (such as when I issue the --help option to my app)? Likewise, should I keep sending error messages to stderr on EXIT_FAILURE ? Or should I send all help and error messages to stdout ? What are general conventions for this with POSIX-compliant UNIX applications? 回答1: Clearly error messages should go to stderr , because you don't want to capture them

Temporary redirection of stderr in a bash script

送分小仙女□ 提交于 2019-12-10 15:44:38
问题 I have a simple script which is used to start another program. This other program may sometimes yield a SIGSEGV , which disrupts my output. I have therefore added a couple of lines which is supposed to temporarily redirect the stderr to /dev/null such that the SIGSEGV is ignored. The following is a draft of my code: exec 2> /dev/null progname >& ./tmp/run.txt && run_status='OK' exec 2>1 The problem is that the last line does not do what I want. The first line obviously works, and redirects

Is it possible to disable stderr in C++?

倖福魔咒の 提交于 2019-12-10 15:44:10
问题 I wrote a program for linux using libxml2 for html parsing. Although it does its job, the html parser writes lots of various errors to stderr. Is it possible to disable stderr at all (or redirect it to /dev/null while not having to run it with a redirecting shell script)? I can live with having to write my own errors to stdout, I just want to get rid of these errors. 回答1: Use freopen to redirect to dev/null: freopen("/dev/null", "w", stderr); 回答2: freopen() ing stderr has already been

Python `print` passing extra text to sys.stdout?

浪子不回头ぞ 提交于 2019-12-10 14:09:06
问题 This is probably something stupid I am missing but it has really got me hung up on a larger project ( c extension) that I am writing. Why is print "Hello, World!" passing None and an extra \n to sys.stdout here? >>> import sys >>> class StdOutHook: ... def write(self, text): ... sys.__stdout__.write("stdout hook received text: %s\n" % repr(text)) ... >>> class StdErrHook: ... def write(self, text): ... sys.__stderr__.write("stderr hook received text: %s\n" % repr(text)) ... >>> sys.stdout =

How to redirect stderr to a file for the whole pipe?

假如想象 提交于 2019-12-10 13:58:37
问题 I am running a command like this: mycmd1 | mycmd2 | mycmd3 | lp Is there a way to redirect stderr to a file for the whole pipe instead of repeating it for each command? That is to say, I'd rather avoid doing this: mycmd1 2>/myfile | mycmd2 2>/myfile | mycmd3 2>/myfile | lp 2>/myfile 回答1: Either { mycmd1 | mycmd2 | mycmd3 | lp; } 2>> logfile or ( mycmd1 | mycmd2 | mycmd3 | lp ) 2>> logfile will work. (The first version might be have a slightly faster (~1ms) startup time depending on the shell)

PBSPro qsub output error file directed to path with jobid in name

狂风中的少年 提交于 2019-12-10 11:35:33
问题 I'm using PBSPro and am trying to use qsub command line to submit a job but can't seem to get the output and error files to be named how I want them. Currently using: qsub -N ${subjobname_short} \ -o ${path}.o{$PBS_JOBID} -e ${path}.e${PBS_JOBID} ... submission_script.sc Where $path=fulljobname (i.e. more than 15 characters) I'm aware that $PBS_JOBID won't be set until after the job is submitted... Any ideas? Thanks 回答1: The solution I came up with was following the qsub command with a qalter

Python sys.stderr flush frequency

我怕爱的太早我们不能终老 提交于 2019-12-10 03:48:50
问题 How often does sys.stderr flush its buffer, and is this standard among different environments? >>> import sys >>> sys.__stderr__ <open file '<stderr>', mode 'w' at 0x2b4fcb7ac270> I see that it is just a standard file type, but I don't know what value of buffering it's supposed to be. dir() does not seem to yield any useful information either. 回答1: On Python 2, I can't find where in the documentation sys.stderr 's buffering is specified. I'd expect the same behaviour as stderr in C that is

Python网络编程

99封情书 提交于 2019-12-09 16:21:47
一、基于TCP协议的socket套接字编程 1、套接字工作流程 先从服务器端说起。服务器端先初始化Socket,然后与端口绑定(bind),对端口进行监听(listen),调用accept阻塞,等待客户端连接。在这时如果有个客户端初始化一个Socket,然后连接服务器(connect),如果连接成功,这时客户端与服务器端的连接就建立了。客户端发送数据请求,服务器端接收请求并处理请求,然后把回应数据发送给客户端,客户端读取数据,最后关闭连接,一次交互结束,使用以下Python代码实现: import socket # socket_family 可以是 AF_UNIX 或 AF_INET。socket_type 可以是 SOCK_STREAM 或 SOCK_DGRAM。protocol 一般不填,默认值为 0 socket.socket(socket_family, socket_type, protocal=0) # 获取tcp/ip套接字 tcpSock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # 获取udp/ip套接字 udpSock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) 1、 服务端套接字函数 s. bind ():绑定(主机,端口号)到套接字 s.

How do you use Log4j to write/capture stdout and stderr to a file and using Windows and Tomcat 5.5 (Java)?

不打扰是莪最后的温柔 提交于 2019-12-09 16:11:55
问题 I am using Windows 2008 R2 and Apache Tomcat 5.5, for your information. STDOUT and STDERR can be automatically logged through Apache Tomcat properties, via Logging tab -> Redirect Stdout and Redirect Stderror textboxes. But I want to control this through log4j. I'm trying to leverage ConsoleAppender and the TimeAndSizeRollingAppender class to rollover what would normally be controlled by Apache Tomcat's innate logging. Basically, however Tomcat redirects stdout and stderr to a file, I want to

Why does wget output to stderr rather than stdout?

非 Y 不嫁゛ 提交于 2019-12-09 15:07:56
问题 After 30mins of futile attempt to capture the output of wget , I figured out that the program writes to stderr rather than the stdout . Searching in web and stack-overflow reveals this to be a well-known fact. Any idea why is this so? 回答1: It's well known, because it's in the manual. Reporting messages on stderr is common, because messages are separated from regular output on stdout . This is useful when you combine several tools with a pipe. In this case it would be bad, when regular output