Skip to main content
Aecorn
Inspiring
July 13, 2018
Question

Wait until external pythonscript exists before reading stdout

  • July 13, 2018
  • 0 replies
  • 604 views

I have a Photoshop extension, that will communicate with an external Python process, by writing a jsonfile to a directory, and then createProcess with the path to the json as a system variable in the call. The python-script does its thing and should report back with a note_id: in a print/stdout statement. Its working kinda, but my javascript isnt waiting for the python to exit() before reading the stdout. So im not actually getting the full stdout from python...

Can createProcess handle a callback? Can I check if the PID is running? Can I trigger the stdout after I know the python-subprocess is done somehow?

var pyCall = window.cep.process.createProcess("C:\\Python27\\python.exe", scriptPath,  result);

var pyErr = window.cep.process.stderr(pyCall.data, function(errMsg) {

lblSync.innerHTML = "Python error: " + errMsg.split('RuntimeError:').pop() + "- Please contact IT.";

});

if (pyErr.err == 0) {

lblSync.innerHTML = "Synced at " +  hr + ":" + min;

}

var pyOut = window.cep.process.stdout(pyCall.data, function(outMsg) {

lblSync.innerHTML = lblSync.innerHTML + " <br />StdOut: " + outMsg;

if (outMsg.indexOf("note_id") !== -1){

var note_id = outMsg.split('note_id:').pop();

if (!isNaN(note_id)){

lblSync.innerHTML = lblSync.innerHTML + '<br /> Guessing that note ID is: "' + note_id + '".';

} else {

lblSync.innerHTML = lblSync.innerHTML + '<br /> The presumed note ID: "' + note_id + '", does not seem to be a number...';

}

} else {

lblSync.innerHTML = lblSync.innerHTML + '<br /> No note_id found...';

});

}

This topic has been closed for replies.