1

I have the following external asynchronous code, that I need to run from my python script (external.js):

var i = o
setInterval(function(){
    i++;
    console.log('item ' + i);//I need to evoke processOutput function on every console.log
}, 1000)

What I need to do in my python script is to catch every output portion(console.log) from external script and handle it:

import subprocess  

def processOutput( consoleLogFromExternal )
    #do stuff

proc = subprocess.Popen(['phantomjs', 'external.js'], 
                        stdout=processOutput)         #doesn't work, of course

Are there any ways to do this? Solution on Python 2.7 would be great.

Helvdan
  • 416
  • 4
  • 14
  • http://stackoverflow.com/questions/2502833/store-output-of-subprocess-popen-call-in-a-string – sobolevn Jun 15 '15 at 17:28
  • @sobolevn I need some sort of event firing on output change, because external.js is meant to loop forever. In your example they only store output in variable, which is not the same task I'm trying to achieve. – Helvdan Jun 15 '15 at 20:53
  • You can extend the variable class and check the input on `write`. – sobolevn Jun 16 '15 at 03:42

0 Answers0