问题描述
感谢您点击这个问题。 我正在尝试在没有外部库的情况下重新启动 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',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)
任何帮助将非常感激!
解决方法
更改为:
function restartProcess() {
spawn(process.argv[1],process.argv.slice(2),{
detached: true,stdio: ['ignore',process.stdout,process.stderr]
}).unref()