node.js exec和bash脚本

时间:2021-08-20 21:59:47

I am using nodejs. The idea is to launch a bash script using exec. I can do it. In my bash script I am doing a video conversion using mencoder. For exemple:

我正在使用nodejs。我们的想法是使用exec启动一个bash脚本。我能做到。在我的bash脚本中,我正在使用mencoder进行视频转换。举个例子:

mencoder Videoinput.ogv -o videouput.avi   -oac lavc -ovc lavc -lavcopts vbitrate=3000 vcodec=mpeg4

The problem I have: If I try to convert a huge video, the conversion is ok until a specific time. In my case 1minute 47 seconds..... So it seems like node has a time maximum to execute a bash script using exec and then it cuts it. Am I right? Does anyone know how to add more time to the exec command? If that is possible, I would be able to finish the video conversion ... thanks for your answer.

我遇到的问题:如果我尝试转换一个巨大的视频,转换是可以的,直到特定的时间。在我的情况下1分钟47秒.....所以似乎节点有一个时间最大值来执行使用exec的bash脚本然后它削减它。我对吗?有谁知道如何为exec命令添加更多时间?如果可以,我将能够完成视频转换...感谢您的回答。

1 个解决方案

#1


1  

It makes sense that js does not allow subprocesses to run more than a specific time. Otherwise the browser can easily become unresponsive.

有意义的是,js不允许子进程运行超过特定时间。否则,浏览器很容易变得无法响应。

I'd propose to run a command which terminates quickly but has started the mencoder in a split-off parallel process. It could be enough to append a & to the mencode command, putting it into the background by this. Maybe you would like to send all its output in a specific file (or at least to /dev/null to suppress it completely). Use > outputfilename for this. Probably redirecting the error message also makes sense, so also use 2> errormessagesfilename or just use 2>&1 after redirecting the standard output to send both streams into the same file.

我建议运行一个快速终止但在分离并行进程中启动了mencoder的命令。它可能足以将一个&附加到mencode命令,由此将其放入后台。也许您希望将其所有输出发送到特定文件中(或至少发送到/ dev / null以完全抑制它)。为此使用> outputfilename。可能重定向错误消息也是有意义的,因此在重定向标准输出以将两个流发送到同一文件之后,也可以使用2> errormessagesfilename或仅使用2>&1。

Maybe you have to create a subshell to fool js into believing the subprocess is finished early. This can eb done by putting the command into parentheses ((mencoder …)).

也许你必须创建一个子shell来欺骗js以相信子进程提前完成。这可以通过将命令放入括号((mencoder ...))来完成。

So you might end up with sth like this:

所以你最终可能会这样:

(mencoder Videoinput.ogv \
    -o videouput.avi \
    -oac lavc \
    -ovc lavc \
    -lavcopts vbitrate=3000 vcodec=mpeg4 \
    >/tmp/mencoder.output 2>&1 &) > /dev/null

#1


1  

It makes sense that js does not allow subprocesses to run more than a specific time. Otherwise the browser can easily become unresponsive.

有意义的是,js不允许子进程运行超过特定时间。否则,浏览器很容易变得无法响应。

I'd propose to run a command which terminates quickly but has started the mencoder in a split-off parallel process. It could be enough to append a & to the mencode command, putting it into the background by this. Maybe you would like to send all its output in a specific file (or at least to /dev/null to suppress it completely). Use > outputfilename for this. Probably redirecting the error message also makes sense, so also use 2> errormessagesfilename or just use 2>&1 after redirecting the standard output to send both streams into the same file.

我建议运行一个快速终止但在分离并行进程中启动了mencoder的命令。它可能足以将一个&附加到mencode命令,由此将其放入后台。也许您希望将其所有输出发送到特定文件中(或至少发送到/ dev / null以完全抑制它)。为此使用> outputfilename。可能重定向错误消息也是有意义的,因此在重定向标准输出以将两个流发送到同一文件之后,也可以使用2> errormessagesfilename或仅使用2>&1。

Maybe you have to create a subshell to fool js into believing the subprocess is finished early. This can eb done by putting the command into parentheses ((mencoder …)).

也许你必须创建一个子shell来欺骗js以相信子进程提前完成。这可以通过将命令放入括号((mencoder ...))来完成。

So you might end up with sth like this:

所以你最终可能会这样:

(mencoder Videoinput.ogv \
    -o videouput.avi \
    -oac lavc \
    -ovc lavc \
    -lavcopts vbitrate=3000 vcodec=mpeg4 \
    >/tmp/mencoder.output 2>&1 &) > /dev/null