如何使用python'Popen'函数执行带有'readp'的bash

2024-09-27 04:27:17 发布

您现在位置:Python中文网/ 问答频道 /正文

我有两个脚本文件'来电.py'和'阅读.sh'

这是我的来电.py'

# -*- coding: utf-8 -*
from subprocess import PIPE, Popen

p = Popen('echo abc', stdin=PIPE, stdout=PIPE, stderr=PIPE, bufsize=1, shell=True)
print 'pid is: ' + str(p.pid)
print p.stdout.read()

p = Popen('bash read.sh', stdin=PIPE, stdout=PIPE, stderr=PIPE, bufsize=1, shell=True)
print 'pid is: ' + str(p.pid)
p.stdin.write('testinput\n')
print p.stdout.read()

这就是阅读.sh你知道吗

#!/bin/bash
read -p "please input:" a
echo 'a is: ' $a

我用python2.7运行

python caller.py

输出为:

pid is: 13535
abc

pid is: 13536
a is:  testinput

我的问题是'read -p'“的提示在哪里,应该有”请在输出中输入:“?你知道吗


Tags: pyechoreadisshstderrstdinstdout

热门问题