简体   繁体   English

在node.js脚本中运行两个脚本

[英]Run two scripts in a node.js script

I am trying to run two executables in a node.js "scripts" section. 我正在尝试在node.js“脚本”部分中运行两个可执行文件。 One of them is a node.js executable (let's call it proc1 ) , and the other is http-server for serving some static assets. 其中一个是node.js可执行文件(我们将其称为proc1 ),另一个是用于提供一些静态资产的http-server These are both process that run continuously. 这些都是连续运行的过程。 I'd like a way to manage these together, so that they start together, and can both be stopped together. 我想要一种将它们一起管理的方法,以便它们一起开始,并且可以一起停止。 I also want to be able to see the output of the cosmos command. 我还希望能够看到cosmos命令的输出。

I tried configuring it like this: 我试过像这样配置它:

"scripts": {
    "build": "http-server >> /dev/null &; proc1",
}

But this gives out the error: 但这给出了错误:

sh: -c: line 0: syntax error near unexpected token ;' sh: -c: line 0: sh:-c:第0行:意外令牌附近的语法错误;' sh: -c: line 0: ;' sh: -c: line 0: http-server &; ;' sh: -c: line 0: http服务器&; proc1' PROC1'

I tried to find a simple node.js process management solution to run this alongside, but couldn't find an appropriate one (similar to supervisor in the Python world). 我试图找到一种简单的node.js流程管理解决方案来与之同时运行,但是找不到合适的解决方案(类似于Python世界中的supervisor )。

Any ideas what to do? 有什么想法怎么办?

仅创建另一个node.js脚本来启动/停止这两个服务器。

sh: -c: line 0: syntax error near unexpected token ;' sh: -c: line 0: sh:-c:第0行:意外令牌附近的语法错误;' sh: -c: line 0: ;' sh: -c: line 0: http-server &; ;' sh: -c: line 0: http服务器&; proc1' PROC1'

The error is in your shell code. 错误出在您的Shell代码中。 Change it to 更改为

"http-server >> /dev/null & proc1",

You can't end a statement with & , to run in the background, and also end it with ; 您不能以&结束语句以在后台运行,也不能以;结尾 .

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM