Pythonスクリプトからbashスクリプトを一時停止したいのですが、手順は次のようになります。
python script reader.py から script writer.sh を起動します。
writer.sh が 3 行目を出力したら、このスクリプトの実行を .ini のコマンドを使用して一時停止し
reader.pyます。で何らかのコマンドを使用して writer.sh の実行を再開したいと考えてい
reader.pyます。
これらの 2 つのスクリプトは次のとおりです。問題は、writer.shsleep コマンドが で実行されたときに一時停止しないことreader.pyです。writer.shだから私の質問は、文字列「3番目」を出力するときにどのように一時停止できますか? 正確に言うと (これは私の仕事での実際の問題です)の出力の読み取りwriter.shを停止したため、停止したいと思います。reader.pywriter.sh
reader.py:
import subprocess
from time import sleep
print 'One line at a time:'
proc = subprocess.Popen('./writer.sh',
shell=False,
stdout=subprocess.PIPE,
)
try:
for i in range(4):
output = proc.stdout.readline()
print output.rstrip()
if i == 2:
print "sleeping"
sleep(200000000000000)
except KeyboardInterrupt:
remainder = proc.communicate()[0]
print "remainder:"
print remainder
writer.sh:
#!/bin/sh
echo first;
echo second;
echo third;
echo fourth;
echo fith;
touch end_file;
関連する質問は、script1 がテキスト行を出力する場合、Linux でパイプを使用するscript1 | script2と script1 が一時停止しますか?