if(typeof JSON!=='object'){JSON={};} (function(){'use strict';function f(n){return n<10?'0'+n:n;} if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+ f(this.getUTCMonth()+1)+'-'+ f(this.getUTCDate())+'T'+ f(this.getUTCHours())+':'+ f(this.getUTCMinutes())+':'+ f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};} var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';} function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);} if(typeof rep==='function'){value=rep.call(holder,key,value);} switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';} gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i 0) { UIALogger.logMessage(forceFlush); } }, output: function (msg) { UIALogger.logMessage(JSON.stringify({"output":msg})); if (forceFlush.length > 0) { UIALogger.logMessage(forceFlush); } } }; })(); var target = UIATarget.localTarget(), host = target.host(); var expectedIndex = 0,//expected index of next command actualIndex,//actual index of next command by reading commandPath index,//index of ':' char in command exp,//expression to be eval'ed result,//result of eval input,//command process;//host command process while (true) { target.delay(0.2); try { process = host.performTaskWithPathArgumentsTimeout("/bin/cat", [commandPath], 2); } catch (e) { Log.output("Timeout on cat..."); continue; } if (process.exitCode != 0) { Log.output("unable to execute /bin/cat " + commandPath + " exitCode " + process.exitCode + ". Error: " + process.stderr); } else { input = process.stdout; try { index = input.indexOf(":", 0); if (index > -1) { actualIndex = parseInt(input.substring(0,index),10); if (!isNaN(actualIndex) && actualIndex >= expectedIndex) { exp = input.substring(index+1, input.length); result = eval(exp); } else {//likely old command is lingering... continue; } } else { continue; } } catch (err) { Log.result("error", err.toString() + " " + (err.stack ? err.stack.toString() : "")); expectedIndex++; continue; } expectedIndex++; Log.result("success",result); } }