public function run()
    {
        $output = array();

        $fragment = <<<FRAGMENT
casper.then(function () {
    this.echo('$this->TAG_CURRENT_URL' + this.getCurrentUrl());
    this.echo('$this->TAG_CURRENT_TITLE' + this.getTitle());
    this.echo('$this->TAG_CURRENT_PAGE_CONTENT' + this.getPageContent().replace(new RegExp('\\r?\\n','g'), ''));
    this.echo('$this->TAG_CURRENT_HTML' + this.getHTML().replace(new RegExp('\\r?\\n','g'), ''));
    this.echo('$this->TAG_CURRENT_HEADERS' + JSON.stringify(this.currentResponse.headers));
    this.echo('$this->TAG_CURRENT_STATUS' + this.currentResponse.status);
    this.echo('$this->TAG_CURRENT_STATUS_TEXT' + this.currentResponse.statusText);
    this.echo('$this->TAG_CURRENT_COOKIES' + JSON.stringify(phantom.cookies));
});

casper.run();

FRAGMENT;

        $this->script .= $fragment;
        $filename = tempnam($this->tempDir, 'php-casperjs-');

        file_put_contents($filename, $this->script);

        // options parsing
        $options = '';
        foreach ($this->options as $option => $value) {
            $options .= ' --' . $option . '=' . $value;
        }

        exec($this->path2casper . 'casperjs ' . $filename . $options, $output);
        if (empty($output)) {
            throw new \Exception('Can not find CasperJS.');
        }

        $this->setOutput($output);
        $this->processOutput();

        unlink($filename);

        return $output;
    }
public function run()
    {
        $output = array();

        $fragment = <<<FRAGMENT
casper.then(function () {
    this.echo('$this->TAG_CURRENT_URL' + this.getCurrentUrl());
    this.echo('$this->TAG_CURRENT_TITLE' + this.getTitle());
    this.echo('$this->TAG_CURRENT_PAGE_CONTENT' + this.getPageContent().replace(new RegExp('\\r?\\n','g'), ''));
    this.echo('$this->TAG_CURRENT_HTML' + this.getHTML().replace(new RegExp('\\r?\\n','g'), ''));
    this.echo('$this->TAG_CURRENT_HEADERS' + JSON.stringify(this.currentResponse.headers));
    this.echo('$this->TAG_CURRENT_STATUS' + this.currentResponse.status);
    this.echo('$this->TAG_CURRENT_STATUS_TEXT' + this.currentResponse.statusText);
    this.echo('$this->TAG_CURRENT_COOKIES' + JSON.stringify(phantom.cookies));
});

casper.run();

FRAGMENT;

        $this->script .= $fragment;
        $filename = tempnam($this->tempDir, 'php-casperjs-');

        file_put_contents($filename, $this->script);

        // options parsing
        $options = '';
        foreach ($this->options as $option => $value) {
            $options .= ' --' . $option . '=' . $value;
        }

        exec($this->path2casper . 'casperjs ' . $filename . $options, $output);
        if (empty($output)) {
            throw new \Exception('Can not find CasperJS.');
        }

        $this->setOutput($output);
        $this->processOutput();

        unlink($filename);

        return $output;
    }
public function run ( ) { $ output = array ( ) ; $ fragment =  <<<FRAGMENT
casper.then(function () {
    this.echo('$this->TAG_CURRENT_URL' + this.getCurrentUrl());
    this.echo('$this->TAG_CURRENT_TITLE' + this.getTitle());
    this.echo('$this->TAG_CURRENT_PAGE_CONTENT' + this.getPageContent().replace(new RegExp('\\r?\\n','g'), ''));
    this.echo('$this->TAG_CURRENT_HTML' + this.getHTML().replace(new RegExp('\\r?\\n','g'), ''));
    this.echo('$this->TAG_CURRENT_HEADERS' + JSON.stringify(this.currentResponse.headers));
    this.echo('$this->TAG_CURRENT_STATUS' + this.currentResponse.status);
    this.echo('$this->TAG_CURRENT_STATUS_TEXT' + this.currentResponse.statusText);
    this.echo('$this->TAG_CURRENT_COOKIES' + JSON.stringify(phantom.cookies));
});

casper.run();

FRAGMENT ; $ this -> script .= $ fragment ; $ filename = tempnam ( $ this -> tempDir , 'php-casperjs-' ) ; file_put_contents ( $ filename , $ this -> script ) ; // options parsing $ options = '' ; foreach ( $ this -> options as $ option => $ value ) { $ options .= ' --' . $ option . '=' . $ value ; } exec ( $ this -> path2casper . 'casperjs ' . $ filename . $ options , $ output ) ; if ( empty ( $ output ) ) { throw new \ Exception ( 'Can not find CasperJS.' ) ; } $ this -> setOutput ( $ output ) ; $ this -> processOutput ( ) ; unlink ( $ filename ) ; return $ output ; }
run the casperJS script and return the stdOut
in using the output variable

@return array
@throws \Exception
run the casperJS script and return the stdOut in using the output variable