I have a javascript application who need to start a linux application. Since I did not found any way to start the application and get when it end, I made a bash script wich launch the application, and send a message via a named pipe when the app close.
Until here, all 's good, but I can t find a way to catch this message in the javascript.
Did someone know how to get the message in the javascript?
I did search, but I only found how to do this in C# and C++.
Sample from the javascript:
var test = spawn('sh', ['home/pi/play.sh', data.video_id]);
Just spawn a bash command wich start the script with the name of the video
Sample from the bash:
mkfifo btjpipe
if pgrep omxplayer
then
echo "AR">btjpipe
else
clear
omxplayer $1 > dev/null
echo "VE">btjpipe
Created the pipe, seeking if the player is already running, then either send AR ("Already Running") or start the player and send VE ("Video End").
use child_process module and child.stdout to pipe the output where you want
var spawn = require('child_process').spawn;
var test = spawn('sh', ['home/pi/play.sh', data.video_id]);
test.stdin.pipe(process.stdin);
test.stdout.pipe(process.stdout);
test.stderr.pipe(process.stderr);
on this case to the current process
Maybe you can also trying using "exec" instead of spawn, you will get the output in the callback function.