I am working with PhantomJS and have a file named file1.js
which has the following code:
var fs = require('fs');
system = require('system');
var inputfile=system.args[1];
var stream = fs.open(inputfile,'r');
var data = stream.read();
var config = JSON.parse(data);
var user_input=config.input;
var output_format=config.output;
stream.close();
The above code reads a JSON file and takes the user_input
and output_format
that were stored in the JSON file.
I have another file as well that is named as file2.js
and now I want to call file2.js
here from inside file1.js
and want to pass both user_input
and output_format
as arguments.
The code of file2.js
doesn't need to be added here.
The important thing is that file1.js
should call file2.js
and pass these two arguments to it. file2.js
will then perform the required operations on those arguments.
I tried injectJS but it doesn't work since it only works with pages e.g. page.injectJS
.
Also, injectJS only accepts one parameter which is a filename and nothing else. Thus, I am unable to achieve what I wanna achieve.
Please help me. Thanks in advance.