title: subprocess stdout into a variable for Ngrok
body: <p>I'm trying to make a python script wich reports me the port on 0.tcp.ngrok.io is started when I run the code on terminal (after moving ngrok executable file to /usr/local/bin)</p>
  <p><code>ngrok tcp 22</code></p>
  <p>I get ths kind of output</p>
  <pre><code>ngrok by @inconshreveable                                       (Ctrl+C to quit)
                                                                                  
  Session Status                connecting                                        
  Version                       2.2.4                                             
  Region                        United States (us)                                
  Web Interface                 http://127.0.0.1:4041                             
  Forwarding                    tcp://0.tcp.ngrok.io:13014 -&gt; localhost:22                                                                                 
  Connections                   ttl     opn     rt1     rt5     p50     p90       
                                0       0       0.00    0.00    0.00    0.00  
  </code></pre>
  <p>My first attempt is to log the subprocess stdout to a variable , but as the stdout is cyclic the stdout.read() never ends this is the code</p>
  <pre><code>import subprocess
  
  ngrok = subprocess.Popen(['ngrok','tcp','22'],stdout = subprocess.PIPE)
  
  output_text = ngrok.stdout.read() # script stops here forever
  
  [**code for getting domain:port from output_text**]
  </code></pre>
  <p>how can I get a &quot;snapshot&quot; of stdout to a variable , without stoping ngrok?</p>
  <p>Is there another way of doing this (next try would be a webscraper on localhost , but it would be nice to have this knowledge for other commands , such as &quot;top&quot;)</p>
  <p>thanks in advance</p>