Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
133 views
in Technique[技术] by (71.8m points)

node.js - NodeJS Javascript: Restart Process

Thanks you for clicking on this question. I am trying to restart a nodeJS process, without external libraries. I did this code:

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()
})

But, when restartProcess() is called, i get error:

C:UsersToshibaDesktopprogrammineflayerspbotot.js:7
      stdio: ['ignore', out, err]
                        ^

ReferenceError: out is not defined
    at restartProcess (C:UsersToshibaDesktopprogrammineflayerspbotot.js:7:25)
    at EventEmitter.<anonymous> (bot.js:54:5)
    at EventEmitter.emit (events.js:315:20)
    at Client.<anonymous> (C:UsersToshiba
ode_modulesmineflayerlibpluginskick.js:5:9)
    at Client.emit (events.js:315:20)
    at FullPacketParser.<anonymous> (C:UsersToshiba
ode_modulesminecraft-protocolsrcclient.js:89:12)
    at FullPacketParser.emit (events.js:315:20)
    at addChunk (C:UsersToshiba
ode_modules
eadable-streamlib\_stream_readable.js:298:12)
    at readableAddChunk (C:UsersToshiba
ode_modules
eadable-streamlib\_stream_readable.js:280:11)
    at FullPacketParser.Readable.push (C:UsersToshiba
ode_modules
eadable-streamlib\_stream_readable.js:241:10)

Any help would be VERY appreciated!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Change to:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...