Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pause bash script from python script?
    text
    copied!<p>I want to pause bash script from python script, the steps look like this: </p> <ol> <li><p>I start script writer.sh from python script reader.py.</p></li> <li><p>When writer.sh outputs third line I want executing of this script to be paused using some command in <code>reader.py</code>.</p></li> <li><p>I want to resume execution of writer.sh using some command in <code>reader.py</code>.</p></li> </ol> <p>Here are those two scripts, the problem is that <code>writer.sh</code> doesn't pause when sleep command is executed in <code>reader.py</code>. So my question is, how can I pause <code>writer.sh</code> when it outputs string "third"? To be exact (this is my practical problem in my job) I want <code>writer.sh</code> to stop because <code>reader.py</code> stopped reading output of <code>writer.sh</code>.</p> <p><code>reader.py</code>:</p> <pre><code>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 </code></pre> <p><code>writer.sh</code>:</p> <pre><code>#!/bin/sh echo first; echo second; echo third; echo fourth; echo fith; touch end_file; </code></pre> <p>Related question is, will using pipes on Linux pause script1, if script1 outputs lines of text, e.g. <code>script1 | script2</code>, and script2 pauses after reading third line of input?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload