简体   繁体   English

如何从NodeJS应用程序正确运行bash脚本?

[英]How to run bash script from NodeJS application correctly?

I am running a node application that uses spawn child-process to start this script 我正在运行一个使用spawn子进程启动此脚本的节点应用程序

#!/bin/bash
FILEPATH="$1"
COMPRESSIONPATH="$2"
ffmpeg -i $FILEPATH -vcodec h264 -acodec mp2 $COMPRESSIONPATH
sudo rm $FILEPATH
curl -H "Content-Type:application/json" -X GET 
http://localhost:3000/clovis/api/led

The script never finishes. 该脚本永远不会完成。 If the ffmpeg compression command takes long then x amount of time then the process just stops and holds the process. 如果ffmpeg压缩命令花费的时间很长,那么x的时间就可以停止并保持该过程。 I cant tell so by using the command ps-ef. 我无法通过使用命令ps-ef来告知。 Is there another way to start bash scripts from NodeJS other then spawn? 除了生成以外,还有其他方法可以从NodeJS启动bash脚本吗? Does the NodeJS child-process have a time limit? NodeJS子进程是否有时间限制?

Fixed - Surprised no one solved this before I did. 已修正-惊讶的是没有人在我解决之前解决了这个问题。 The child-process has options you can set to help the process separate itself from the node process. 子进程具有可以设置的选项,以帮助该进程将自身与节点进程分开。

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

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