python调用系统命令
in 后端 with 0 comment

python调用系统命令

in 后端 with 0 comment
import subprocess
import select

pro = subprocess.Popen(
    ["ls","-l"],
    stdin = subprocess.PIPE,
    stdout = subprocess.PIPE)

print("first")
select.select([pro.stdout], [], [])
print(pro.stdout.read().decode())
print("end")
print("---------------")
print("sencond")
pro.stdin.write(b"ls -l\n")
select.select([pro.stdout], [], [])
print(pro.stdout.read().decode() )
print("end")
first
-rw-r--r-- 1 pi   pi       1411 5月  14 18:01 test.py

end
---------------
sencond

end
Responses