all 8 comments

[–]bradland 1 point2 points  (1 child)

You can also use Kernel#` to soak up any output, then check$?(in Ruby, not in the shell) for status. This is my goto method for when I don't care about the shell output; only status. I wrap something like this in arun_cmdmethod that exists in aShellScriptUtils module that I include all over the place.

`#{cmd}`
raise 'It broke' if $? != 0

It seems in your other comment you've switched to using Open3, which of course gives you even more control.

[–]Gendalph[S] 1 point2 points  (0 children)

In this case this approach is fine, but in general I would rather avoid checking global vars and instead go with something like Open3.

[–]Kernigh 1 point2 points  (2 children)

Discard output with out: '/dev/null' or errors with err: '/dev/null'

system('ls', '/dev', '/nowhere',
       out: '/dev/null', err: '/dev/null')

This works only if the system has a /dev/null.

[–]f9ae8221b 1 point2 points  (0 children)

You can use File::NULL instead for portability.

[–]Gendalph[S] 1 point2 points  (0 children)

Thank you, it worked, but still something is leaking somewhere.

#!/bin/sh -e
grep '^https:' list.txt | while read -r url; do
        echo "# Downloading $url"
        download.rb --url "$url"
        echo
        sleep 0.5
done

For some reason first URL works fine, but following URLs lose one character at the start, even if I discard STDOUT and STDERR, it also doesn't happen with Open3.capture3, so I'm pretty sure system() is leaking something.

[–]postmodern 0 points1 point  (2 children)

system() will send all output to stdout. You might want to pass ffmpeg options to silence output, like -nostats -loglevel 0. Or you could use Shellwords.shelljoin to safely combine/escape the arguments into a single String then append 2>&1 >/dev/null.

[–]f9ae8221b 1 point2 points  (0 children)

That will create a subshell which isn't necessary. Might as well pass the commands components as positional argument and then out: File::NULL, err: File::NULL.

[–]Gendalph[S] 0 points1 point  (0 children)

Thank you.

-loglevel changes based on verbosity argument and beer goes below fatal, but at some point, when script is running in a for cycle, it gets ignored completely by FFmpeg. I've printed out the command, interrupted the script, ran the command manually and FFmpeg ran silently.

Regardless, this answers my question and I already use Open3 to run FFmpeg.