while trying to execute following command using exec

java -cp %SIKULI_HOME%\sikuli-script.jar org.python.util.jython E:\automation.sikuli\automation.py "a,b,c" 

am getting following error

var exec = require('child_process').execFile;

postreq.params prints values as a,b,c.i want to pass this with \automation.py "a,b,c" i dodnt know how to pass with below one

 exec('java -cp %SIKULI_HOME%\sikuli-script.jar org.python.util.jython E:\automation.sikuli\automation.py postreq.params', function (err, data) {
    console.log(err);
    console.log(data);
    console.log("Sikuli execution started")
    //  res.end(data);
  });

error

{ [Error: spawn ENOENT] code: 'ENOENT', errno: 'ENOENT', syscall: 'spawn' }

below command is working properly using cmd

java -cp %SIKULI_HOME%\sikuli-script.jar org.python.util.jython E:\automation.sikuli\automation.py "a,b,c"
有帮助吗?

解决方案

The way you explain your problem, postreq.params seems to be a JavaScript variable. If so, this is what you should exec:

var exec = require("child_process").exec;
exec('java -cp %SIKULI_HOME%\sikuli-script.jar org.python.util.jython E:\automation.sikuli\automation.py "' +  postreq.params + '"', function (err, data) {

I'm not a Windows guy so I'm not positive that %SIKULI_HOME% will be expanded like you want. If not, then using process.env.HOMEPATH like Phoenix suggested in a comment should do the trick:

exec('java -cp ' + proces.env.HOMEPATH + '\sikuli-script.jar org.python.util.jython E:\automation.sikuli\automation.py "' +  postreq.params + '"', function (err, data) {

其他提示

The first argument to execFile is the file to run. You are passing a full set of arguments. Try this:

exec('java',  ['-cp', '%SIKULI_HOME%\sikuli-script.jar',
    'org.python.util.jython', 'E:\automation.sikuli\automation.py',
    'postreq.params'], function (err, data) {

I'm not sure if it will expand %SIKULI_HOME% since I'm not super familiar with Windows.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top