Tag: 退出

在批量启动后退出node.js cmd

我有两个我想调用的batch file,让它们自己closures。 首先,我通过npm更新一个包,更新之后,它应该打包一个vsix扩展。 问题:在调用npm之后,整个batch file的其余部分将被忽略。 有没有人有这个解决方法? 第一个文件: @echo off start /wait nodejs.cmd|echo n>nul tfx extension create –manifest-globs src\vss-extension.json 第二个文件(nodejs.cmd): npm i -g tfx-cli exit 在此先感谢☺

如何定义Node.js状态码而不立即退出?

在Node中, process.exit(code)方法允许用code状态码退出。 然而,我正在寻找的是一种在没有临时定义的情况下定义进程退出的状态代码而不立即退出的方法。 我怎么能做这样的事情?

nodejs:child_process.spawn不报告退出代码

在写一个简单工具的unit testing时,我无法获得以require('child_process').spawn的subprocess的进程退出代码。 为了简化如果下来,考虑这个简单的节点命令退出代码35: SHELL> node -e“process.exit(35)”& [1] 23427 [1] +赛义达35节点-e“process.exit(35)” 现在考虑下面的文件,上面的命令用exec和spawn执行。 目标是捕捉退出代码: shell>猫WTF.js var cp = require('child_process'); cp.exec('node -e“process.exit(35);”',function(err){ console.log('child exit code(exec)',err.code); }); cp.spawn('node',['-e',''process.exit(35);“'])。on('exit',function(code){ console.log('孩子退出代码(spawn)',代码); }); 但是当它运行…惊喜: SHELL>节点WTF.js 子代码退出(exec)35 子代码退出(spawn)0 我在产卵召唤中错过了一些明显的东西吗? SHELL> node –version V6.0.0

在node.js退出之前写入.txt文件

我希望我的服务器在节点退出并在下次加载时保存一些基本数据。 我试着回答这个问题的build议,但服务器似乎closures,才能写入文件。 这是我正在尝试的确切代码: process.stdin.resume(); function exitHandler(options, err) { if(!serverUp){return;} serverUp = false; fs.writeFile('server.txt', String(search_index),function (err) { console.log("debug") // <– This doesn't happen process.exit(); }); } //do something when app is closing process.on('exit', exitHandler.bind(null,{cleanup:true})); //catches ctrl+c event process.on('SIGINT', exitHandler.bind(null, {exit:true})); //catches uncaught exceptions process.on('uncaughtException', exitHandler.bind(null, {exit:true}));

当Node.js进程可以直接退出()而不触发其他信号事件(uncaughtException,SIGINT,SIGTERM …)

我使用REDIS数据存储来处理应用程序。 为了保持数据的完整性,我想在stream程closures时清理商店。 我创build了一个函数处理程序,并绑定它(用process.on())来发信号事件:uncaughtException,SIGINT,SIGTERM,SIGQUIT,它工作正常(CTRL + C,进程查杀,exception,…)。 但是我已经读过,在某些情况下,过程可以直接退出而不触发其他信号事件。 在这种情况下,问题在于process.on('exit')处理程序只能处理同步任务。 我做了不同的testing,试图以不同的方式杀死这个过程。 而且(除了在Windows上使用SIGTERM),我无法确定process.on('exit')是否直接触发而没有SIGINT,SIGTERM或其他事件触发的情况。 所以我的问题是(在Linux系统上),在什么情况下进程可以直接退出而不会触发这个事件: http : //nodejs.org/api/all.html#all_signal_events ?

Node.js拦截process.exit

所以我想在我的node.js程序的末尾运行一个shell命令,然后在退出之前等待输出/打印它。 我尝试了process.on('exit',function(){})并在那里运行了子exec执行命令,但是在callback之前退出了程序。 所以,而是我使用process.exit封闭,但我得到了一些奇怪的结果。 代码的基础是: process.exit = (function(old_exit){ return function(code){ var exec = require('child_process').exec; var child; child = exec("my shell command", function (error, stdout, stderr) { if (error !== null) { console.log('exec error: ' + error); } console.log(stdout); //I first had this as the concluding line: old_exit.apply(process,arguments); //and I also tried old_exit.apply(process,[]); //and even (which I […]

如何停止执行一个node.js脚本?

说我有这个脚本: var thisIsTrue = false; exports.test = function(request,response){ if(thisIsTrue){ response.send('All is good!'); }else{ response.send('ERROR! ERROR!'); // Stop script execution here. } console.log('I do not want this to happen if there is an error.'); } 正如你所看到的,如果出现错误,我想停止脚本执行任何下游函数。 我设法通过增加return;来实现这一点return; 在发送错误响应之后: var thisIsTrue = false; exports.test = function(request,response){ if(thisIsTrue){ response.send('All is good!'); }else{ response.send('ERROR! ERROR!'); return; } console.log('I do […]

正常closures一个节点.JS HTTP服务器

这是我正在工作的一个简单的networking服务器 var server = require("http").createServer(function(req,resp) { resp.writeHead(200,{"Content-Type":"text/plain"}) resp.write("hi") resp.end() server.close() }) server.listen(80, 'localhost') // The shortest webserver you ever did see! Thanks to Node.JS 🙂 除了保持活力以外,它们都很棒。 当第一个请求进来时, server.close被调用。 但是这个过程并没有结束。 实际上,TCP连接仍然是打开的,这就允许另一个请求通过,这是我想要避免的。 我如何closures现有的保持连接?