stderr

基于TCP协议的远程终端控制并发socketserver实现以及粘包问题处理

心已入冬 提交于 2020-01-02 21:21:21
# 客户端 # -*- coding: utf-8 -*- import socketserver import struct import json import subprocess class MyTcpHandler(socketserver.BaseRequestHandler): def handle(self): while True: try: cmd = self.request.recv(1024) if not cmd: break print(cmd.decode('utf-8')) obj = subprocess.Popen(cmd.decode('utf-8'), shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE ) stdout = obj.stdout.read() stderr = obj.stderr.read() # 制作报头 header_dic = { 'file_name': cmd.decode('utf-8'), 'data_size': len(stdout) + len(stderr) } header_json = json.dumps(header_dic) header_bytes = header_json.encode('utf-8') #

node child_process模块

跟風遠走 提交于 2020-01-02 21:00:06
NodeJs是一个单进程的语言,不能像Java那样可以创建多线程来并发执行。当然在大部分情况下,NodeJs是不需要并发执行的,因为它是事件驱动性永不阻塞。但单进程也有个问题就是不能充分利用CPU的多核机制,根据前人的经验,可以通过创建多个进程来充分利用CPU多核,并且Node通过了child_process模块来创建完成多进程的操作。 child_process模块给予node任意创建子进程的能力,node官方文档对于child_proces模块给出了四种方法,映射到操作系统其实都是创建子进程。但对于开发者而已,这几种方法的api有点不同 child_process.exec(command[, options][, callback]) 启动 子进程来执行shell命令,可以通过回调参数来获取脚本shell执行结果 const { exec } = require('child_process'); exec('cat *.js bad_file | wc -l', (error, stdout, stderr) => { if (error) { console.error(`exec error: ${error}`); return; } console.log(`stdout: ${stdout}`); console.log(`stderr: ${stderr}`);

stdin, stdout and stderr are shared between?

做~自己de王妃 提交于 2020-01-02 06:09:10
问题 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

C基础知识(11):错误处理

早过忘川 提交于 2020-01-02 05:01:11
C语言不提供对错误处理的直接支持,但是作为一种系统编程语言,它以返回值的形式允许您访问底层数据。在发生错误时,大多数的C或UNIX函数调用返回1或NULL,同时会设置一个错误代码errno,该错误代码是全局变量,表示在函数调用期间发生了错误。可以在<error.h>头文件中找到各种各样的错误代码。 C语言提供了perror()和strerror()函数来显示与errno相关的文本消息。 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <string.h> 4 #include <errno.h> 5 6 extern int errno; 7 8 int main() { 9 10 int errnum; 11 FILE *pf = NULL; 12 pf = fopen("unexist.txt", "r"); 13 if (pf == NULL) { 14 errnum = errno; 15 // 使用 stderr 文件流来输出所有的错误 16 fprintf(stderr, "Error number: %d\n", errno); // Error number: 2 17 // perror()函数显示您传给它的字符串,后跟一个冒号、一个空格和当前 errno 值的文本表示形式 18 perror(

15、【C语言基础】错误处理、递归

心已入冬 提交于 2020-01-02 05:00:42
C 错误处理 C 语言不提供对错误处理的直接支持,但是作为一种系统编程语言,它以返回值的形式允许您访问底层数据。在发生错误时,大多数的 C 或 UNIX 函数调用返回 1 或 NULL,同时会设置一个错误代码 errno ,该错误代码是全局变量,表示在函数调用期间发生了错误。 您可以在 errno.h 头文件中找到各种各样的错误代码。 所以,C 程序员可以通过检查返回值,然后根据返回值决定采取哪种适当的动作。开发人员应该在程序初始化时,把 errno 设置为 0,这是一种良好的编程习惯。0 值表示程序中没有错误。 errno、perror() 和 strerror() C 语言提供了 perror() 和 strerror() 函数来显示与 errno 相关的文本消息。 perror() 函数显示您传给它的字符串,后跟一个冒号、一个空格和当前 errno 值的文本表示形式。 strerror() 函数,返回一个指针,指针指向当前 errno 值的文本表示形式。 让我们来模拟一种错误情况,尝试打开一个不存在的文件。您可以使用多种方式来输出错误消息,在这里我们使用函数来演示用法。另外有一点需要注意,您应该使用 stderr 文件流来输出所有的错误。 1 #include <stdio.h> 2 #include <errno.h> 3 #include <string.h> 4 5

C 错误处理

戏子无情 提交于 2020-01-02 05:00:07
C 错误处理 C 语言不提供对错误处理的直接支持,但是作为一种系统编程语言,它以返回值的形式允许您访问底层数据。在发生错误时,大多数的 C 或 UNIX 函数调用返回 1 或 NULL,同时会设置一个错误代码 errno ,该错误代码是全局变量,表示在函数调用期间发生了错误。您可以在 <error.h> 头文件中找到各种各样的错误代码。 所以,C 程序员可以通过检查返回值,然后根据返回值决定采取哪种适当的动作。开发人员应该在程序初始化时,把 errno 设置为 0,这是一种良好的编程习惯。0 值表示程序中没有错误。 errno、perror() 和 strerror() C 语言提供了 perror() 和 strerror() 函数来显示与 errno 相关的文本消息。 perror() 函数显示您传给它的字符串,后跟一个冒号、一个空格和当前 errno 值的文本表示形式。 strerror() 函数,返回一个指针,指针指向当前 errno 值的文本表示形式。 让我们来模拟一种错误情况,尝试打开一个不存在的文件。您可以使用多种方式来输出错误消息,在这里我们使用函数来演示用法。另外有一点需要注意,您应该使用 stderr 文件流来输出所有的错误。 #include <stdio.h> #include <errno.h> #include <string.h> extern int

Print STDOUT/STDERR and write them to a file in Bash?

纵饮孤独 提交于 2020-01-01 09:18:15
问题 Is there a way to have Bash redirect STDOUT/STDERR to a file yet still print them out to the terminal as well? 回答1: This will redirect both STDOUT and STDERR to the same file: some_command 2>&1 | tee file.log Example $ touch foo; ls foo asfdsafsadf 2>&1 | tee file.log ls: asfdsafsadf: No such file or directory foo $ cat file.log ls: asfdsafsadf: No such file or directory foo 回答2: Use the tee command. $ echo "hi" | tee output.txt hi [unix]$ ls output.txt [unix]$ cat output.txt hi 来源: https:/

Prevent Ghostscript from writing errors to standard output

谁都会走 提交于 2020-01-01 05:40:07
问题 I'm using Ghostscript to rasterize the first page of a PDF file to JPEG. To avoid creating tempfiles, the PDF data is piped into Ghoscripts's stdin and the JPEG is "drained" on stdout. This pipeline works like a charm until GS receives invalid PDF data: Instead of reporting all error messages on stderr as I would have expected, it still writes some of the messages to stdout instead. To reproduce: $ echo "Not a PDF" >test.txt $ /usr/bin/gs -q -sDEVICE=jpeg -dBATCH -dNOPAUSE -dFirstPage=1

How to view stderr of PHP's ldap_* functions (with LDAP_OPT_DEBUG_LEVEL=7) from mod_php

ⅰ亾dé卋堺 提交于 2019-12-31 02:52:12
问题 I can run the following from the PHP 5.4.16 CLI: ldap_set_option(NULL, LDAP_OPT_DEBUG_LEVEL, 7); $conn = ldap_connect($hostname); ldap_bind($conn, $ldaprdn); And I will get a lot of debug output to stderr that starts like this: ldap_create ldap_url_parse_ext(ldaps://ldap.example.com) ldap_bind_s ldap_simple_bind_s ldap_sasl_bind_s ldap_sasl_bind ldap_send_initial_request ... That is great for debugging on the CLI. However, I need to debug from within Apache 2.2.15 mod_php because I am seeing

C: how to redirect stderr from System-command to stdout or file?

可紊 提交于 2019-12-30 06:24:18
问题 The shell command $ avrdude -c usbtiny outputs text to stderr. I cannot read it with commmands such as head-less-more cos it is not stdout. I want the text to stdout or to a file. How can I do it in C? I have tried to solve the problem by my last question but still unsolved. 回答1: I've not tried something like this in OpenBSD, but in at least a few *nix-like systems, you can do this using dup2 . #include <unistd.h> #include <stdio.h> int main(void) { fprintf(stderr, "This goes to stderr\n");