use phantomJS from nodeJS and pass arguments to a js file

im trying to use phantomJS from nodeJS as spawn process, at this point is so fine, the problem cames when i try to pass some arguments to the js file used by phantomJS, how can do that?

here is my code:

spawn = require("child_process").spawn;
phantom = spawn("/usr/bin/phantomjs", [
                "phantom_js_file.js",
                "x xxx xxx xxx" ] );

where the x are the arguments for the phantom_js_file.js

in my phantom_js_file.js i get the arguments like this:

var arg = require("system").args,
    tip = arg[1],
    rl = arg[2],
    er = arg[3],
    cod = arg[4],

any ideas are appreciated. regards.

You need to pass the arguments as an array of arguments, where whitespace in your "what you'd normally use" commands signal array delimiters.

If you'd call it normally as "phantomjs myfile.js arg1 arg2 arg3" you need to use the spawn call:

spawn("phantomjs", ["myfile.js","arg1","arg1","arg3"]);

So no spaces in any of those arguments. If there's a space, it becomes a new array entry. That even goes for things like "somecommand -d thisdir". It doesn't matter that the "-d" and "thisdir" belong together, spawn needs them separated:

spawn("somecommand", ["-d","thisdir"]);