0

I have a command

omxplayer /home/pi/videos/9886a3n2545r7i505rzz.mp4 -o alsa:sysdefault

It runs fine from the command line, but if I translate that command to a spawn command:

let omxProcess = spawn('omxplayer', ['/home/pi/videos/9886a3n2545r7i505rzz.mp4', '-o', 'alsa:sysdefault'])

The command fails (without any error).

But if I run the following removing the :sysdefault it runs (But without the :sysdefault, the command is not the same and I need to run it with :sysdefault

  let omxProcess = spawn('omxplayer', ['/home/pi/videos/9886a3n2545r7i505rzz.mp4', '-o', 'alsa'])

I'm thinking it has to do with having an ":" in the arg.

Any thoughts?

Jason Small
  • 1,064
  • 1
  • 13
  • 29

1 Answers1

0

Since you're not using the shell: true flag, it's almost certainly not caused by the : in the command. You can always verify this, just to be on the safe side.

An easy way to check if the environment is messing with your arguments is calling another binary, for example echo, instead of omxplayer. Does it echo back your arguments? Is the colon still there?

The binary is probably exitting with some error code (and possibly an error message). To capture them, be sure to register handlers on the output streams, as well as an exit handler that should tell you the exit code. This is outlined in the child_process docs, right below spawn(). Adapted for your case:

omxProcess.stdout.on('data', (data) => {
  console.log(`stdout: ${data}`);
});

omxProcess.stderr.on('data', (data) => {
  console.error(`stderr: ${data}`);
});

omxProcess.on('close', (code) => {
  console.log(`child process exited with code ${code}`);
});

Based on the output and the exit code, you should be able to debug the issue.

Robert Kawecki
  • 2,218
  • 1
  • 9
  • 17
  • Thanks for the advice. I ran an echo and the command is correct. I'm running this inside an electron app. Do you think that may have something to do with it? I don't see any messages in the console when the command doesn't exicute properly, but running it with out the :sysdefault i do get an output after the file is done playing. – Jason Small Mar 24 '21 at 20:52
  • I am not sure - if in doubt, make a minimal example (plain Node.js) and try it out on your target system. Standard troubleshooting tools like `strace -p` could be helpful in identifying lock-ups on syscalls. – Robert Kawecki Mar 24 '21 at 22:52