Source:
public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) { PrintStream originalStdOut = System.out; ByteArrayOutputStream bytesOutput = new ByteArrayOutputStream(); File tmpFile = null; try { tmpFile = PigUtils.createTempPigScript(cmd); System.setOut(new PrintStream(bytesOutput)); ScriptState.start(pigServer.getPigContext().getExecutionEngine().instantiateScriptState()); PigStats.start(pigServer.getPigContext().getExecutionEngine().instantiatePigStats()); PigScriptListener scriptListener = new PigScriptListener(); ScriptState.get().registerListener(scriptListener); listenerMap.put(contextInterpreter.getParagraphId(), scriptListener); pigServer.registerScript(tmpFile.getAbsolutePath()); } catch (IOException e) { if (e instanceof FrontendException) { FrontendException fe = (FrontendException) e; if (!fe.getMessage().contains("Backend error :")) { return new InterpreterResult(Code.ERROR, ExceptionUtils.getStackTrace(e)); } } PigStats stats = PigStats.get(); if (stats != null) { String errorMsg = PigUtils.extactJobStats(stats); if (errorMsg != null) { LOGGER.debug("Error Message:" + errorMsg); return new InterpreterResult(Code.ERROR, errorMsg); } } return new InterpreterResult(Code.ERROR, ExceptionUtils.getStackTrace(e)); } finally { System.setOut(originalStdOut); listenerMap.remove(contextInterpreter.getParagraphId()); if (tmpFile != null) { tmpFile.delete(); } } StringBuilder outputBuilder = new StringBuilder(); PigStats stats = PigStats.get(); if (stats != null && includeJobStats) { String jobStats = PigUtils.extactJobStats(stats); if (jobStats != null) { outputBuilder.append(jobStats); } } if (!outputBuilder.toString().isEmpty() || !bytesOutput.toString().isEmpty()) { outputBuilder.append("------------- Pig Output --------------\n"); } outputBuilder.append(bytesOutput.toString()); return new InterpreterResult(Code.SUCCESS, outputBuilder.toString()); }

Target:
public InterpreterResult interpret(String cmd, InterpreterContext contextInterpreter) { PrintStream originalStdOut = System.out; ByteArrayOutputStream bytesOutput = new ByteArrayOutputStream(); File tmpFile = null; try { tmpFile = PigUtils.createTempPigScript(cmd); System.setOut(new PrintStream(bytesOutput)); ScriptState.start(pigServer.getPigContext().getExecutionEngine().instantiateScriptState()); PigStats.start(pigServer.getPigContext().getExecutionEngine().instantiatePigStats()); PigScriptListener scriptListener = new PigScriptListener(); ScriptState.get().registerListener(scriptListener); listenerMap.put(contextInterpreter.getParagraphId(), scriptListener); pigServer.registerScript(tmpFile.getAbsolutePath()); } catch (IOException e) { if (e instanceof FrontendException) { FrontendException fe = (FrontendException) e; if (!fe.getMessage().contains("Backend error :")) { LOGGER.error("Fail to run pig script.", e); return new InterpreterResult(Code.ERROR, ExceptionUtils.getStackTrace(e)); } } PigStats stats = PigStats.get(); if (stats != null) { String errorMsg = PigUtils.extactJobStats(stats); if (errorMsg != null) { LOGGER.error("Fail to run pig script, " + errorMsg); return new InterpreterResult(Code.ERROR, errorMsg); } } LOGGER.error("Fail to run pig script.", e); return new InterpreterResult(Code.ERROR, ExceptionUtils.getStackTrace(e)); } finally { System.setOut(originalStdOut); listenerMap.remove(contextInterpreter.getParagraphId()); if (tmpFile != null) { tmpFile.delete(); } } StringBuilder outputBuilder = new StringBuilder(); PigStats stats = PigStats.get(); if (stats != null && includeJobStats) { String jobStats = PigUtils.extactJobStats(stats); if (jobStats != null) { outputBuilder.append(jobStats); } } outputBuilder.append(bytesOutput.toString()); return new InterpreterResult(Code.SUCCESS, outputBuilder.toString()); }