提问者:小点点

NodeJS JavaScript:重新启动进程


感谢您点击这个问题。我试图在没有外部库的情况下重新启动一个nodeJS进程。我做了这样的代码:

function restartProcess() {
spawn(process.argv[1], process.argv.slice(2), {
  detached: true, 
  stdio: ['ignore', out, err]
}).unref()
process.exit()
}
bot.on( "kicked", (reason) => {
    console.log("KICKED! "+ reason)
    restartProcess()
})

但是,当调用restartProcess()时,我会得到错误:

C:\Users\Toshiba\Desktop\program\mineflayer\spbot\bot.js:7
      stdio: ['ignore', out, err]
                        ^

ReferenceError: out is not defined
    at restartProcess (C:\Users\Toshiba\Desktop\program\mineflayer\spbot\bot.js:7:25)
    at EventEmitter.<anonymous> (bot.js:54:5)
    at EventEmitter.emit (events.js:315:20)
    at Client.<anonymous> (C:\Users\Toshiba\node_modules\mineflayer\lib\plugins\kick.js:5:9)
    at Client.emit (events.js:315:20)
    at FullPacketParser.<anonymous> (C:\Users\Toshiba\node_modules\minecraft-protocol\src\client.js:89:12)
    at FullPacketParser.emit (events.js:315:20)
    at addChunk (C:\Users\Toshiba\node_modules\readable-stream\lib\_stream_readable.js:298:12)
    at readableAddChunk (C:\Users\Toshiba\node_modules\readable-stream\lib\_stream_readable.js:280:11)
    at FullPacketParser.Readable.push (C:\Users\Toshiba\node_modules\readable-stream\lib\_stream_readable.js:241:10)

如有任何帮助,我们将不胜感激!


共1个答案

匿名用户

更改为:

function restartProcess() {
spawn(process.argv[1], process.argv.slice(2), {
  detached: true, 
  stdio: ['ignore', process.stdout, process.stderr]
}).unref()