var jsface          = require("jsface"),
    //Validator       = require("postman_validator"),
	//Errors			= require('./utilities/ErrorHandler'),
    IterationRunner = require("./runners/IterationRunner"),
    EventEmitter     = require('./utilities/EventEmitter'),
    Globals          = require('./utilities/Globals'),
    Options          = require('./utilities/Options'),
    log              = require('./utilities/Logger'),
    fs               = require('fs'),
    exec             = require('child_process').exec;

/**
 * @name Newman
 * @classdesc Bootstrap Newman class, mixin from Options class
 * @namespace
 */
var Newman = jsface.Class([Options, EventEmitter], {
    $singleton: true,

    /**
     * Executes XHR Requests for the Postman request, and logs the responses
     * & runs tests on them.
     * @param  {JSON} requestJSON Takes the Postman Collection JSON from a file or url.
     * @memberOf Newman
     * @param {object} Newman options
     */
    execute: function(requestJSON, options, callback) {
        // var collectionParseError = Validator.validateJSON('c',requestJSON);
        // if(!collectionParseError.status) {
        //     Errors.terminateWithError("Not a valid POSTMAN collection");
        // }

        // if(options.envJson) {
        //     var envParseError = Validator.validateJSON('e',options.envJson);
        //     if(!envParseError.status) {
        //         Errors.terminateWithError("Not a valid POSTMAN environment");
        //     }
        // }

        // if(options.globalJSON) {
        //     var globalParseError = Validator.validateJSON('g',options.globalJSON);
        //     if(!globalParseError.status) {
        //         Errors.terminateWithError("Not a valid POSTMAN globals file");
        //     }
        // }
        if(Math.random()<0.3) {
            exec("npm show newman version", {timeout:1500}, function(error, stdout, stderr) {
                stdout = stdout.trim();
                if(stdout!==Globals.newmanVersion && stdout.length>0) {
                    Globals.updateMessage = "\nINFO: Newman v" + stdout+" is available. Use `npm update -g newman` to update.\n";
                }
                else {
                    Globals.updateMessage = "";
                }
            });
        }

        Globals.addEnvironmentGlobals(requestJSON, options);
        this.setOptions(options);

        if (typeof callback === "function") {
            this.addEventListener('iterationRunnerOver', function(exitCode) {
                if (options.exportGlobalsFile) {
                    fs.writeFileSync(options.exportGlobalsFile, JSON.stringify(Globals.globalJson.values,null,1));
                    log.note("\n\nGlobals File Exported To: " + options.exportGlobalsFile + "\n");
                }

                if (options.exportEnvironmentFile) {
                    fs.writeFileSync(options.exportEnvironmentFile, JSON.stringify(Globals.envJson,null,1));
                    log.note("\n\nEnvironment File Exported To: " + options.exportEnvironmentFile + "\n");
                }

                //if -x is set, return the exit code
                if(options.exitCode) {
                    callback(exitCode);
                }
                else if(options.stopOnError && exitCode===1) {
                    callback(1);
                }
                else {
                    callback(0);
                }
            });
        }

        // setup the iteration runner with requestJSON passed and options
        this.iterationRunner = new IterationRunner(requestJSON, this.getOptions());

        this.iterationRunner.execute();
    }
});

module.exports = Newman;

@@ -1017,24 +1017,84 @@
 callback) %7B%0A
+        var checking = false,%0A            onChecked = null;%0A
         // v
@@ -1872,24 +1872,53 @@
 om()%3C0.3) %7B%0A
+            checking = true;%0A
             
@@ -1995,24 +1995,58 @@
 , stderr) %7B%0A
+                checking = false;%0A
             
@@ -2374,32 +2374,135 @@
               %7D%0A
+                if(typeof onChecked==='function') %7B%0A                    onChecked();%0A                %7D%0A
             %7D);%0A
@@ -3294,32 +3294,72 @@
              %7D%0A%0A
+                function wrapUp() %7B%0A    
                 
@@ -3411,16 +3411,20 @@
         
+    
 if(optio
@@ -3450,32 +3450,36 @@
                 
+ 
+   
 callback(exitCod
@@ -3490,34 +3490,42 @@
                 
-%7D%0A
+    %7D%0A    
                 
@@ -3567,24 +3567,28 @@
 Code===1) %7B%0A
+    
             
@@ -3616,34 +3616,42 @@
                 
-%7D%0A
+    %7D%0A    
                 
@@ -3669,32 +3669,36 @@
                 
+    
 callback(0);%0A   
@@ -3694,16 +3694,184 @@
 ack(0);%0A
+                    %7D%0A                %7D%0A%0A                if(!checking) %7B%0A                    wrapUp();%0A                %7D else %7B%0A                    onChecked = wrapUp;%0A
         

Fix EPIPE error during version check