繁体   English   中英

节点应用程序中的python-shell

[英]python-shell from a node application

题:

如何在节点应用程序中运行python脚本?

这有效:

从命令行运行此命令,它可以正常工作。

python generatePersonTerraform.py -s http://localhost:8080/api/person/239/exportPersonGeneration

在Node server.js中不起作用的代码

var PythonShell = require('python-shell');
...

var runPythonRoutine = function (request, response) {
    var PythonShell = require('python-shell');
    var options = {
        mode: 'text',
        pythonPath: 'python',
        pythonOptions: ['-s'],
        scriptPath: '.',
        args: ['http://localhost:8080/api/person/135/exportPersonGeneration']
    };
    PythonShell.run('generatePersonTerraform.py', options, function (err, results) {
       console.log(err);
    });
}

错误:

    at PythonShell.parseError (/root/my-app/node_modules/python-shell/index.js:191:17)
    at terminateIfNeeded (/root/my-app/node_modules/python-shell/index.js:98:28)
    at ChildProcess.<anonymous> (/root/my-app/node_modules/python-shell/index.js:89:9)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:194:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
  executable: 'python',
  options: [ '-s' ],
  script: 'generatePersonTerraform.py',
  args: [ 'http://localhost:8080/api/person/239/exportPersonGeneration' ],
  exitCode: 1 }

注意

我一直在尝试使用https://www.npmjs.com/package/python-shell

编辑1

我将选项更改为:

var options = {
    mode: 'text',
    pythonPath: 'python',
    pythonOptions: [],
    scriptPath: '.',
    args: ['-s', 'http://localhost:8080/api/serviceType/135/exportPluginGeneration']
};

并得到此错误:

    at PythonShell.parseError (/root/my-app/node_modules/python-shell/index.js:191:17)
    at terminateIfNeeded (/root/my-app/node_modules/python-shell/index.js:98:28)
    at ChildProcess.<anonymous> (/root/my-app/node_modules/python-shell/index.js:89:9)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:194:7)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:215:12)
  executable: 'python',
  options: null,
  script: 'generatePersonTerraform.py',
  args: 
   [ '-s',
     'http://localhost:8080/api/person/135/exportPersonGeneration' ],
  exitCode: 0 }

但是,它也可以运行并起作用,只是使节点应用程序停滞了。 因此,如果我弄清楚如何使其不失速,那我就很好。 python脚本似乎可以构建所有应有的文件。

'-s'应该在args ,而不是pythonOptions

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM