search

Home  >  Q&A  >  body text

node.js - nodejs中使用shelljs模块的exec方法执行shell脚本命令,但是会多次执行,不知道为什么呢

nodejs中使用shelljs模块的exec方法执行shell脚本命令,但是会多次执行,不知道为什么呢。 代码很简单,如下

start文件:

#!/usr/bin/env node

var shelljs = require('shelljs/global');
exec('node --version');

执行start, 终端显示:

v0.10.29
v0.10.29
v0.10.29
v0.10.29
v0.10.29
v0.10.29
v0.10.29
v0.10.29
v0.10.29
v0.10.29
v0.10.29

有的时候只展示1次,有的时候两行,也有可能是3,4,5,6... n 行, 有时候又没有执行。 so why

ringa_leeringa_lee2875 days ago599

reply all(2)I'll reply

  • 黄舟

    黄舟2017-04-17 14:02:05

    Uninstall and install again

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-17 14:02:05

    Can you try the local writing method of shelljs? Check whether the local writing method is normal.

    var shell = require('shelljs');
    shell.exec('node --version');

    reply
    0
  • Cancelreply