yarek
yarek

Reputation: 12034

How casperjs passing arguments with space?

casperjs script.js "myurl" "myemail" "my name"

Here is the script:

url = (casper.cli.get(0));
email = (casper.cli.get(1));
name = (casper.cli.get(2));

this.echo(name);
console.log(name);

The result is: my (and not my name).

I also tried with single quotes.

Upvotes: 1

Views: 585

Answers (1)

dasmelch
dasmelch

Reputation: 532

You can just escape the spaces with a backslash and DON'T use quotes, for example:

 casperjs test.js myurl myemail my\ name

I don't know for sure if it is dependend to the console you are using, under ubuntu (docker) that worked for me:

var casper = require('casper').create();
var targetUrl = 'http://www.test.com/';

casper.start(targetUrl, function() {
  url = (casper.cli.get(0));
  email = (casper.cli.get(1));
  name = (casper.cli.get(2));
  this.echo(url);
  this.echo(email);
  this.echo(name);
  console.log(name);
});

casper.run();

Result was:

myurl
myemail
my name
my name

For a windows command line that worked:

casperjs test.js myurl myemail \"my name\"

Upvotes: 4

Related Questions