0

Okay so i have a casperjs script which does a specific task for me then echoes a result back to me.

i normally use the command

Casperjs script.js "variable1" "variable2"

after a few moments it will echo a results saying either

True

or

False

how can i use php on my server instead of using the command line i would like the php script to execute the command above and then echo the result back to me on my php page

1 Answer 1

1

You can use PHP's shell_exec which uses php to call your command, like so:

.php

$casperjs = "casperjs";
$script = "script.js";
$arg0 = $variable1; 
$arg1 = $variable2;
$command = "$casperjs $script $arg0 $arg1";
$result = shell_exec($command);
echo $result;   

script.js

var casper = require('casper').create();
var arg0 = casper.cli.get(0);
var arg1 = casper.cli.get(1);
casper.start('http://example.com/', function() {
  if (this.getTitle() == 'blahblah') {
    this.echo('True');
  } else {
    this.echo('False');
  }
});     
casper.run();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.