stderr

第四十九篇 socket套接字编程

匿名 (未验证) 提交于 2019-12-02 23:48:02
Ŀ¼ 数据从客户端---->服务端的协议 客户端请求连接服务端的过程需要经过三次握手 1.客户端首先会向服务端发出请求,这个请求中会带有一个SYN报头 2.服务端会接收到客户端的请求,然后响应客户端,并把SYN报头返回给客户端,而且返回的数据中会加一个ACK报头 3.客户端开始建立连接状态,并发送一条请求,这条请求带上返回的ACK报头,让服务端也进入连接状态 1.客户端首先发送带FIN报头的请求给服务端,请求断开连接 2.服务端接收到客户端的请求后,返回一个带ACK报头的确认请求,来表明同意断开 3.但由于可能会存在数据没有传输完全的情况,所以服务端还不会马上断开,它会等数据全部传输完毕之后,发送一条带上返回的FIN报头的请求给客户端 4.最后客户端收到请求后,返回带有ACK报头的数据给服务端,服务端接到数据之后,断开连接 1 # 自定义服务端 import socket # 1.定义一个符合TCP协议的服务端 server = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # TCP协议 # 2.绑定IP地址 server.bind(('127.0.0.1', 8000)) # 127.0.0.1 代表本地 # 8000 端口 # server.bind(('192.168.11.196', 8000)) #

Redirecting stdout/stderr to multiple files

早过忘川 提交于 2019-12-02 23:28:28
I was wondering how to redirect stderr to multiple outputs. I tried it with this script, but I couldn't get it to work quite right. The first file should have both stdout and stderr, and the 2nd should just have errors. perl script.pl &> errorTestnormal.out &2> errorTest.out Is there a better way to do this? Any help would be much appreciated. Thank you. perl script.pl 2>&1 >errorTestnormal.out | tee -a errorTestnormal.out > errorTest.out Will do what you want. This is a bit messy, lets go through it step by step. We say what used to go to STDERR will now go STDOUT We say what used to go to

Python中subprocess学习

匿名 (未验证) 提交于 2019-12-02 22:56:40
生命不息奋斗不止! subprocess的目的就是启动一个新的进程并且与之通信。 subprocess模块中只定义了一个类: Popen。可以使用Popen来创建进程,并与进程进行复杂的交互。它的构造函数如下: subprocess.Popen(args, bufsize=0, executable=None, stdin=None, stdout=None, stderr=None, preexec_fn=None, close_fds=False, shell=False, cwd=None, env=None, universal_newlines=False, startupinfo=None, creationflags=0) 参数args可以是字符串或者序列类型(如:list,元组),用于指定进程的可执行文件及其参数。如果是序列类型,第一个元素通常是可执行文件的路径。我们也可以显式的使用executeable参数来指定可执行文件的路径。 参数stdin, stdout, stderr分别表示程序的标准输入、输出、错误句柄。他们可以是PIPE,文件描述符或文件对象,也可以设置为None,表示从父进程继承。 如果参数shell设为true,程序将通过shell来执行。 参数env是字典类型,用于指定子进程的环境变量。如果env = None,子进程的环境变量将从父进程中继承

python内置模块介绍(一)

匿名 (未验证) 提交于 2019-12-02 22:51:30
os sys re time datetime random shutil Subprocess os模块 os.path下方法 最后访问 时间 最后权限修改 时间 最后内容修改 时间 没有小括号 sys模块 re模块 re模块的函数介绍 list形式 返回 正则表达式符号含义 ǰ 的字符 0次或多次 ǰ 一个字符 1次或多次 ǰ 一个字符 0次或1次 匹配 ǰ 一个字符 至少m次 分组还可以细分,普通分组,命名分组,后向引用,前向肯定断言,后向肯定断言,前向否定断言、后向否定断言 普通分组 ,则是通过1,2.....来获取匹配到信息,如re.search(r"(abc)","abcdefg").group(1) 命名分组 ,则是通过给分组命名来获取匹配到的信息,如 ( ?P<name>正则表达式),这里的命名就是name,通过groupdict("name")函数获取捕获值 其他用的不多 \d和\D,\w和\W,\s和\S每一对都是对方的补集,一起可以组成全部的字符 time模块 在time模块中有3中标示时间的方式:1.时间戳,2.格式化的时间字符串,3.元祖(struct_time,有9个元素) UTC(Coordinated Universal Time,协调世界时),世界标准时间,中国是UTC+8;DST(Daylight Saving Time)夏令时 时间戳

python通过SSH登陆linux并操作

匿名 (未验证) 提交于 2019-12-02 21:59:42
使用python通过SSH登陆linux并操作 用的昨天刚接触到的库,在windows下通过paramiko来登录linux系统并执行了几个命令,基本算是初试成功,后面会接着学习的。 代码: >>> ssh = paramiko.SSHClient() >>> ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy()) >>> ssh.connect(‘10.104.6.8‘,username = ‘xiaopeng‘,password=‘******‘) >>> stdin,stdout,stderr = ssh.exec_command(cmd) >>> stdin,stdout,stderr = ssh.exec_command(cmd) >>> stdin,stdout,stderr = ssh.exec_command(cmd) [‘code\n‘, ‘Desktop\n‘, ‘order.cpp\n‘, ‘python\n‘, ‘test\n‘, ‘\xe5\x85\xac\xe5\x85\xb1\xe7\x9a\x84\n‘, ‘\xe6\xa8\xa1\xe6\x9d\xbf\n‘, ‘\xe8\xa7\x86\xe9\xa2\x91\n‘, ‘\xe5\x9b\xbe\xe7\x89\x87\n‘, ‘

管道及I/O重定向

匿名 (未验证) 提交于 2019-12-02 21:59:42
管道符"|":前一个命令的输出,作为后一个命令的输入 命令1 | 命令2 | 命令3 | ... # 输出"hello,world."并将小写转换为大写 [root@localhost ~]# echo "hello,world." | tr 'a-z' 'A-Z' HELLO,WORLD. # 显示passwd文件中按:分割的每行第一个部分并排序并将小写转换为大写 [root@localhost ~]# cut -d: -f1 /etc/passwd | sort | tr 'a-z' 'A-Z' ADM APACHE BIN DAEMON DBUS FEDORA 简单的解释就是捕捉一个文件, 命令, 程序, 脚本, 或者甚至是脚本中的代码块的输出, 然后将这些输出作为输入发送到另一个文件, 命令, 程序, 或脚本中。 执行一个shell命令行时通常会自动打开三个标准文件,即标准输入文件(stdin),通常对应终端的键盘;标准输出文件(stdout)和标准错误输出文件(stderr),这两个文件都对应终端的屏幕。 进程将从标准输入文件中得到输入数据,将正常输出数据输出到标准输出文件,而将错误信息送到标准错误文件中。 习惯上,标准输入(standard input)的文件描述符是 0,标准输出(standard output)是 1,标准错误(standard error)是 2。

文件描述符与重定向

蹲街弑〆低调 提交于 2019-12-02 11:43:38
文件描述符简介 : 文件描述符在形式上是一个非负整数,每一个文件描述符会与一个打开文件相对应,内核 利用文件描述符来访问文件,最广为人知的文件描述符有stdin(标准输入),stdout(标准输出),stderr(标准错误),系统分别事先为它们保留了三个文件描述符0,1,2,我们也可以通过特殊命令给我们的的文件指定文件描述符。 重定向的意思 :Linux中,IO 重定向 是将某一个文件描述符的内容转移到另一个指定的文件描述符中 , 通常与文件描述符有关。 最常用的我们可以将标准输出的内容重定向到指定文件中。通过重定向操作符(>和>>)可以将输出发送到文件中,而不是终端。>和>>略有差异,尽管两者都可以将文本重定向到文件, 但是前者会清空文件,再写入内容 ,后者会将内容 追加 到现有的文件的尾部, 默认情况下,重定向操作符针对的是标准输出 ,所以>等同于1>,类似的>>等同与1>>。 1:标准输出和标准错误重定向 2:利用<操作符将文件读入stdin 3:自定义文件描述符 4:tee命令 1:例如echo命令就是将指定的字符串送到标准输出,那么我们就可以结合echo命令将指定字符串发送到指定的文件: 在这里就是将文件描述符stdout(1)的内容通过重定向操作符重定向到了test.txt文件里。 在处理错误时,来自stderr的输出被倾倒入了文件/dev/null中,/dev

Duplicate stdout, stderr in QTextEdit widget

南楼画角 提交于 2019-12-02 07:39:11
问题 I've been having difficulty with my PySide program for a few days now. I don't think the problem is incredibly difficult because there are answer out there. Problem I have is none of them seem to work for me. I want to 'listen' to the file objects stdout and stderr and output the contents to QText Edit widget while my PySide program is running. Now, I already realise this question (or something similar) has been asked before on here but like I said, can't get it to work for me for some reason

Redirect stdout and stderr to same file using Python

拥有回忆 提交于 2019-12-02 07:26:56
问题 I would like to redirect the standard error and standard output of a Python script to the same output file. From the terminal I could use $ python myfile.py &> out.txt to do the same task that I want, but I need to do it from the Python script itself. I looked into the questions Redirect subprocess stderr to stdout, How to redirect stderr in Python?, and Example 10.10 from here, and then I tried the following: import sys fsock = open('out.txt', 'w') sys.stdout = sys.stderr = fsock print "a"

Duplicate stdout, stderr in QTextEdit widget

不问归期 提交于 2019-12-02 07:17:43
I've been having difficulty with my PySide program for a few days now. I don't think the problem is incredibly difficult because there are answer out there. Problem I have is none of them seem to work for me. I want to 'listen' to the file objects stdout and stderr and output the contents to QText Edit widget while my PySide program is running. Now, I already realise this question (or something similar) has been asked before on here but like I said, can't get it to work for me for some reason and most other solutions out there are based on the one that I can't get working, so a very