From the Naked
docs:
The execute_js() function runs the execute() function on a Node.js script file. Instead of passing the command to be executed as the first parameter, pass a Node.js script filepath as the first parameter and any additional command arguments as the second parameter (optional)
So the problem is not in python but in the Node.js
program.
Here you can find a description on how to pass arguments to a node program when running from console.
I think the solution to your problem is to change the node program as follows:
var pi = process.argv[2];
console.log(pi);
Where you pick the third argument since the first two are respectively the node.js path and the current program path.
UPDATE: if you want to pass more than 1 variable, you simply have to pass all the variables as a blank separated string as the second argument of execute_js
.
Example:
Python side
pi = 8
rho = 10
arg_in = f"{pi} {rho}" # for older versions of python you can use "{pi} {rho}".format(pi=pi, rho=rho)
response = execute_js('file.js', arg_in)
Js side
var pi = process.argv[2],
rho = process.argv[3];
console.log(pi, rho)
You can pass as many arguments as you want, adapting this with lists and for cycles, you can pass a dynamic number of arguments.