subprocess模块允许你去创建一个新的进程让其执行另外的程序,并与它进行通信,获取标准的输入、标准输出、标准错误以及返回码等。更多查看官网:https://docs.python.org/2/library/subprocess.html?highlight=subprocess#frequently-used-arguments
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
|
import subprocess import subprocess ''' sh-3.2# ls /Users/nick/Desktop |grep txt$ mysql.txt tt.txt 事物.txt '''
res1 = subprocess.Popen('ls /Users/jieli/Desktop', shell=True, stdout=subprocess.PIPE) res = subprocess.Popen('grep txt$', shell=True, stdin=res1.stdout, stdout=subprocess.PIPE)
print(res.stdout.read().decode('utf-8'))
|