[英]Returning a value to shell script from a node.js file
I am calling a NodeJS file like this in a shell script: 我在shell脚本中调用这样的NodeJS文件:
$ node process.js
$ let "errors |= $?"
I want to see if the process.js file returned any errors. 我想看看process.js文件是否返回任何错误。 How do I return a value inside process.js file so that I can capture it in my shell script.
如何在process.js文件中返回一个值,以便我可以在shell脚本中捕获它。
You can set the exitCode (and let the node process die naturally): 您可以设置exitCode(并让节点进程自然死亡):
process.exitCode = 1
Or you can force-kill it: 或者你可以强行杀死它:
process.exit(1)
in both cases it will return 1
as the exit code. 在这两种情况下,它将返回
1
作为退出代码。
https://nodejs.org/api/process.html#process_process_exit_code https://nodejs.org/api/process.html#process_process_exit_code
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.