我们可以用代码而不是文件或命令运行节点js子进程吗?

时间:2016-07-01 13:11:13

标签: node.js child-process

我有一种情况,我希望在子进程中运行一些代码(一些调用API)。那么,我们可以在子进程中运行代码而不是文件或命令吗? - 旧

现在我使用了这段代码:

<code>process = require('child_process');
                var ls = process.spawnSync('node','lookUp.js ' + serialNumber);
                ls.stdout.on('data', function(data) {
                 console.log('stdout: ' + data);
                }); </code>

收到了这个错误:

<code>
child_process.js:1254
  for (i = 0; i < options.stdio.length; i++) {
                               ^
TypeError: Cannot read property 'length' of undefined
    at Object.spawnSync (child_process.js:1254:32)
    at /home/eweba1-pc-22/htdocs/geoAdmin/myAdminTester/zohocrm-myadmin-module-to-get-devices/service2.js:252:22
    at Object.whilst (/home/eweba1-pc-22/htdocs/geoAdmin/myAdminTester/zohocrm-myadmin-module-to-get-devices/node_modules/async/dist/async.js:4578:9)
    at Request._callback (/home/eweba1-pc-22/htdocs/geoAdmin/myAdminTester/zohocrm-myadmin-module-to-get-devices/service2.js:211:10)
    at Request.self.callback (/home/eweba1-pc-22/htdocs/geoAdmin/myAdminTester/zohocrm-myadmin-module-to-get-devices/node_modules/request/request.js:200:22)
    at Request.EventEmitter.emit (events.js:110:17)
    at Request.<anonymous> (/home/eweba1-pc-22/htdocs/geoAdmin/myAdminTester/zohocrm-myadmin-module-to-get-devices/node_modules/request/request.js:1067:10)
    at Request.EventEmitter.emit (events.js:129:20)
    at IncomingMessage.<anonymous> (/home/eweba1-pc-22/htdocs/geoAdmin/myAdminTester/zohocrm-myadmin-module-to-get-devices/node_modules/request/request.js:988:12)
    at IncomingMessage.EventEmitter.emit (events.js:129:20)
</code>

0 个答案:

没有答案