stderr

stdin, stdout and stderr are shared between?

非 Y 不嫁゛ 提交于 2019-12-05 17:56:48
I am trying to understand the behavior of the three streams - stdout , stdin and stderr . I couldn't get the answer from any textbook, so I came here. I know that these three are stored in file descriptor table with file descriptors 0 (stdin), 1 (stdout) and 2 (stderr). I am also aware that these are not merely file descriptors but I/O streams which can be redirected. Ok, so how about sharing? Consider the three cases: When a fork() is called : The child process and parent process shares file descriptors, but do they have the same stdin, stdout and stderr ? When a thread is created : Threads

Redirecting stdout & stderr from background process

时光怂恿深爱的人放手 提交于 2019-12-05 16:22:03
I have a script called foo that runs the program a.exe and sends the timing statistics to a file, time.log #!/bin/bash date 1>> time.log (time ./a.exe) 2>> time.log This works if I run the script in the background of my terminal and keep my shell open until a.exe finishes, but if I run the script in the background and exit my terminal (a.exe takes a long time to run) foo & exit when I come back, a.exe has executed but the time statistics do not appear in my log file. Does anyone know why this is? Is there a way to get the timing statistics after I've closed the parent shell? thanks nohup foo &

suppress scapy warning message when importing the module

拜拜、爱过 提交于 2019-12-05 13:33:56
问题 I'm writing a small script, that gathers some information using scapy and then returns some xml code, that I'll pass on to the xmlrpc interface of metasploit. I'd like it that my script only returns xml, and no additional warnings etc. I can suppress most scapy output, with adding the option verbose=0 to my sr1 command. What I still get before every output, and I assume it returns this warning when I'm loading the module, is: WARNING: No route found for IPv6 destination :: (no default route?)

Redirecting CGI error output from STDERR to a file (python AND perl)

与世无争的帅哥 提交于 2019-12-05 13:32:52
I'm moving a website to Hostmonster and asked where the server log is located so I can automatically scan it for CGI errors. I was told, "We're sorry, but we do not have cgi errors go to any files that you have access to." For organizational reasons I'm stuck with Hostmonster and this awful policy, so as a workaround I thought maybe I'd modify the CGI scripts to redirect STDERR to a custom log file. I have a lot of scripts (269) so I need an easy way in both Python and Perl to redirect STDERR to a custom log file. Something that accounts for file locking either explicitly or implicitly would

Determining whether STDERR is going to terminal

旧街凉风 提交于 2019-12-05 11:35:50
I have a suite of Java programs which are used as command-line tools on our Linux servers. Most of them use a class that prints a progress bar on STDERR, similar to Perl's Term::ProgressBar . I'd like to have the progress bar shown whenever STDERR is going to the terminal and automatically disable itself when STDERR is redirected so that there aren't all sorts of progress bar pieces in the redirected data. Checking System.console() == null was my first thought, but redirecting STDOUT is enough to make this true , even if STDERR is still going to the terminal. Is there anything I can check that

Delphi - Capture stdout and stderr output from statically linked MSVC++ compiled DLL

久未见 提交于 2019-12-05 09:45:57
I have been trying to capture stdout and stderr output from a DLL compiled in MSVC++ that my Delphi app statically links to, but so far have been unsuccessful. procedure Test; var fs: TFileStream; begin fs := TFileStream.Create('C:\temp\output.log', fmCreate or fmShareDenyWrite); SetStdHandle(STD_OUTPUT_HANDLE, fs.Handle); SetStdHandle(STD_ERROR_HANDLE, fs.Handle); dllFunc(0); // Writes to stdout in MSVC++ console app, but not here // fs.Length is always zero fs.Free; end; Thought I was on the right track, but it does not work. Is SetStdHandle() enough? Is TFileStream the right thing to use

执行命令,粘包问题

爱⌒轻易说出口 提交于 2019-12-05 08:40:11
1.执行命令   在py代码中如何取调用操作系统的命令   新模块:  subprocess r = subprocess.Popen('ls',           shell=True,           stdout=subprocess.PIPE           stderr=subprocess.PIPE # subprocess.Popen(cmd,shell=True,subprocess.stdout,subprocess.stderr) #cmd : 代表系统命令 #shell = True 代表这命令是 系统命令, 告诉操作系统,将cmd当成系统命令去执行 #stdout 是执行完系统命令之后,用于保存结果的一个管道 #stderr 是执行完系统命令之后,用于宝村错误的一个管道 print(r.stdout.read().decode('gbk')) print(r.stderr.read().decode('gbk')) 粘包问题:只有tcp协议才会发送粘包,udp不会发生   EX:   发送端发送数据,接收端不知道应该如何接收,造成的一种数据混乱的现象   在TCP协议中,       有一个合包机制(nagle 算法),将多次连续发送且间隔较小的数据,进行打包成一块数据传送       还有一个机制是拆包机制,在发送端,因为收到网卡的MTU限制

Python sys.stderr flush frequency

元气小坏坏 提交于 2019-12-05 05:43:09
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. jfs 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 unbuffered (except Windows) and I don't know whether c99 standard mandates it. The standard error stream

subprocess模块

南笙酒味 提交于 2019-12-05 00:34:35
ubprocess模块 可以通过python代码给操作系统终端发送命令, 返回结果。 ''' subprocess: sub: 子 process: 进程 ''' import subprocess while True: # 1.让用户输入终端命令 cmd_str = input('请输入终端命令:').strip() # Popen(cmd命令, shell=True, # stdout=subprocess.PIPE, stderr=subprocess.PIPE) # 调用Popen就会将用户的终端命令发送给本地操作系统的终端 # 得到一个对象,对象中包含着正确或错误的结果。 obj = subprocess.Popen( cmd_str, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) success = obj.stdout.read().decode('gbk') if success: print(success, '正确的结果') error = obj.stderr.read().decode('gbk') if error: print(error, '错误的结果') 来源: https://www.cnblogs.com/lvguchujiu/p/11891835.html

SVN post-commit hook sending a message back to client

梦想与她 提交于 2019-12-04 17:43:31
问题 I'm writing a post-commit script in bash, and I'd like to pass messages back to the client who's making a commit. However echo my message >&2 isn't making it back to the client. Is it even possible to send messages back with a post-commit hook? 回答1: Condering a post-commit hook does: anything that the hook printed to stderr will be marshalled back to the client, making it easier to diagnose hook failures. you can check if this isn't a simple quote issue: echo "my message" >&2 You can see in