1

I have a JavaScript application that needs to start a Linux application.

Since I did not find any way to start the application and get when it ends, I made a bash script which launches the application, and sends a message via a named pipe when the app closes.

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 which starts 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").

Jason Aller
  • 3,541
  • 28
  • 38
  • 38
DrakaSAN
  • 7,673
  • 7
  • 52
  • 94
  • What JavaScript engine and environment are you using? NodeJS? SilkJS? – T.J. Crowder Jul 24 '13 at 07:45
  • I m on a raspeberry pi using raspbian (debian for raspberry pi), on chromium, with node.js – DrakaSAN Jul 24 '13 at 07:55
  • I've added the `nodejs` tag (really quite an important one for your question). No idea what you mean by "on chromium" -- if you're using Raspbian, you're not using Chrome OS, and the only other relevant Chromium I can think of is a web browser, but you're not doing this in a web browser. – T.J. Crowder Jul 24 '13 at 07:56
  • I ve seen that, I was editing with some second late, forgot to add it – DrakaSAN Jul 24 '13 at 07:57
  • See http://stackoverflow.com/questions/15466383/how-to-detect-if-a-node-js-script-is-running-through-a-shell-pipe – devnull Jul 24 '13 at 08:34

1 Answers1

2

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.

ElLocoCocoLoco
  • 387
  • 3
  • 11