stderr

Should the command line “usage” be printed on stdout or stderr?

ぃ、小莉子 提交于 2019-11-29 02:08:28
问题 When printing the "usage" of an application, should it be done on stdout or on stderr? Depending on the application I've seen several cases, but there doesn't seem to be one rule. Maybe I'm mistaken and there is one good practice. In that case, what is it? 回答1: Never thought about it, but why not write the usage instructions to stderr if the program was called with no or wrong arguments, and write it to stdout when called with a --help (or similar) argument? This way, if the usage is shown

Node 进程

£可爱£侵袭症+ 提交于 2019-11-29 02:06:23
Node 是一个 Node 是基于 Chrome V8 引擎开发的能使 JavaScript 在服务器端运行的运行时环境。由于 js 的特性,所以 Node 默认也是单线程的,无法充分利用多核CPU。适用于IO密集型,但对于 CPU 密集型的应用,因为需要长时间占用 CPU,会导致其他的请求处于阻塞状态,所以对于 CPU 密集型的应用,需要特殊考虑。当然,Node 也给我们提供了一些 API,用于衍生子进程来进行其他的一些操作。常用的有 child_process 跟 cluster。 1. child_process: 提供了四个 api 来衍生异步子进程   1). child_process.spawn(command[, args][, options]): 默认不会衍生一个 shell, 可通过 options.shell = true 衍生一个 shell 并在该 shell 上执行对于的 command, 但是需要注意的是如果启动了 shell,则不要将未经过处理的用户输入传给 command, 因为这可能会触发一些命令的执行, 比如 ls hello.txt; rm -rf * const { spawn } = require('child_process') const spawnProcess = spawn('cmd.exe', ['/c', 'node

Should I output warnings to STDERR or STDOUT?

感情迁移 提交于 2019-11-28 21:41:30
问题 I'm making a script that handles a predefined set of data, outputting to a file. I want to pop up a warning when one datum (which is always "Regular" in every set that I've had access to) is different stating that this value is unhandled (since I don't know how it affects the data). Should I output this warning to stderr or stdout? 回答1: If I saved the output of this script (i.e. stdout only) so that I could process it later, would that warning interfere with how the output is parsed? Moreover

capture process stdout and stderr in the correct ordering

孤街醉人 提交于 2019-11-28 21:27:32
I launch a process from C# as follows: public bool Execute() { ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.Arguments = "the command"; startInfo.FileName = "C:\\MyApp.exe"; startInfo.UseShellExecute = false; startInfo.RedirectStandardOutput = true; startInfo.RedirectStandardError = true; Log.LogMessage("{0} {1}", startInfo.FileName, startInfo.Arguments); using (Process myProcess = Process.Start(startInfo)) { StringBuilder output = new StringBuilder(); myProcess.OutputDataReceived += delegate(object sender, DataReceivedEventArgs e) { Log.LogMessage(Thread.CurrentThread

Python logging split between stdout and stderr [duplicate]

感情迁移 提交于 2019-11-28 18:53:42
This question already has an answer here: How can INFO and DEBUG logging message be sent to stdout and higher level message to stderr 6 answers 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? 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.getLogger('__name__') logger.setLevel(logging.DEBUG) h1 = logging.StreamHandler(sys.stdout) h1.setLevel(logging.DEBUG) h1

bash: redirect (and append) stdout and stderr to file and terminal and get proper exit status

谁说胖子不能爱 提交于 2019-11-28 18:47:40
问题 To redirect (and append) stdout and stderr to a file, while also displaying it on the terminal, I do this: command 2>&1 | tee -a file.txt However, is there another way to do this such that I get an accurate value for the exit status? That is, if I test $? , I want to see the exit status of command , not the exit status of tee . I know that I can use ${PIPESTATUS[0]} here instead of $? , but I am looking for another solution that would not involve having to check PIPESTATUS . 回答1: Perhaps you

How to capture stderr on Windows/DOS?

半城伤御伤魂 提交于 2019-11-28 18:12:20
I want to capture the errors from a script into a file instead of to the screen. In *nix, this is done with stderr redirection, usually echo "Error" 2> errorfile.log How do I do it in a CMD script under Windows? aphoria For example: PSKILL NOTEPAD >output.txt 2>&1 This will direct stdout and stderr to a file name output.txt. See Underused features of Windows batch files for more details. That should work in Win32, too. If you have already redirected stdout, and want stderr redirected to the same file, you must use the 2>& special form, rather than just specifying the same file twice. Otherwise

How to capture stdout/stderr with googletest?

淺唱寂寞╮ 提交于 2019-11-28 17:11:48
Is it possible to capture the stdout and stderr when using the googletest framework? For example, I would like to call a function that writes errors to the console (stderr). Now, when calling the function in the tests, I want to assert that no output appears there. Or, maybe I want to test the error behaviour and want to assert that a certain string gets printed when I (deliberately) produce an error. I have used this snippet before to redirect cout calls to a stringstream when testing output. Hopefully it might spark some ideas. I've never used googletest before. // This can be an ofstream as

什么是粘包现象

不问归期 提交于 2019-11-28 14:41:50
简单远程执行命令程序开发(30分钟) 是时候用户socket干点正事呀,我们来写一个远程执行命令的程序,写一个socket client端在windows端发送指令,一个socket server在Linux端执行命令并返回结果给客户端 执行命令的话,肯定是用我们学过的subprocess模块啦,但 注意注意注意: res = subprocess.Popen(cmd.decode('utf-8'),shell=True,stderr=subprocess.PIPE,stdout=subprocess.PIPE) 命令结果的编码是以当前所在的系统为准的,如果是windows,那么 res.stdout.read()读出的就是GBK编码的 ,在接收端需 要用GBK解码,且只能从管道里读一次结果 ssh server import socket import subprocess ip_port = ('127.0.0.1', 8080) tcp_socket_server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) tcp_socket_server.bind(ip_port) tcp_socket_server.listen(5) while True: conn, addr = tcp_socket_server

模拟ssh远程命令执行

 ̄綄美尐妖づ 提交于 2019-11-28 13:21:25
服务端: import socketimport subprocessphone = socket.socket(socket.AF_INET, socket.SOCK_STREAM)phone.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) #可以重复适用系统端口phone.bind(('192.168.43.14', 8081))phone.listen(5)while True: conn, clent_add = phone.accept() while True: try: #1 接受命令 data = conn.recv(1024) obj = subprocess.Popen(data.decode('utf-8'), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout = obj.stdout.read() stderr = obj.stderr.read() #if not data:break #如果客户端挂掉,此方法适用于linux操作系统 #print(data.decode('utf-8')) #2 执行命令 拿到结果 #3 拔执行命令的结果发送给客户端 conn.send(stdout+stderr) #+