node.js exec and bash script

Problem

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:

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.

Problem courtesy of: anraT

Solution

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

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.

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 …)).

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
Solution courtesy of: Alfe

Discussion

There is currently no discussion for this recipe.

This recipe can be found in it's original form on Stack Over Flow.