Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass arguments to a javascript file #60

Open
iwasa183 opened this issue Aug 3, 2015 · 5 comments
Open

How to pass arguments to a javascript file #60

iwasa183 opened this issue Aug 3, 2015 · 5 comments

Comments

@iwasa183
Copy link

iwasa183 commented Aug 3, 2015

I could run a javascript file named 'highcharts-convert.js' which can generate images of charts on server side.
With original phantomjs command, I just run the command lke below:
%phantomjs highcharts-convert.js -infile option.json -outfile chart.png -scale 4 -width 1000 -constr Chart

I just want to do same thing with phantomjs-gem in ruby program, but I can not find a way to pass arguments, e.g., "-infile option.json -outfile chart.png -scale 4 -width 1000 -constr Chart".

Is it possible to pass arguments to the javascript file with phantomjs-gem?

@michael-misshore
Copy link

Looks like the PhantomJs#run takes in multiple arguments.

https://github.com/colszowka/phantomjs-gem/blob/master/lib/phantomjs.rb#L49

Something like this should work:

Phantomjs.run('highcharts-convert.js', '-infile option.json', '-outfile chart.png', '-scale 4', '-width 1000', '-constr Chart')

@jozefvaclavik
Copy link

I'm sending params to Run as an array of k=v.

options = {
  infile: 'option.json',
  outfile: 'chart.png',
  scale: 4,
  width: 1000,
  constr: 'Chart'
}.collect { |k, v| "#{k}=#{v}" }

Phantomjs.run('highcharts-conver.js', options)

@MaxPleaner
Copy link

how do you use the options in the Javscript file?

process.argv is making the script freeze when read.

@nflorentin
Copy link

nflorentin commented Jul 29, 2016

I personally did it like that:

Phantomjs.run("script.js", "arg1", "arg2")

In script.js:

var system = require('system');
var arg1 = system.args[1];
var arg2 = system.args[2];

@rubystar
Copy link

rubystar commented Sep 25, 2017

@nflorentin This looks more reasonable for my script:

opts = [file, opt1, opt2]
Phantomjs.run(*opts)

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants