Command produces output, but unable to pipe nor send to file

New to Debian (Or Linux in general)? Ask your questions here!

Command produces output, but unable to pipe nor send to file

Postby winny » 2018-08-26 15:01

Background: been using UNIX and Linux since ~1998, but only occasionally and only for server use. All my shell scripts could be considered dirty hacks and once they were working, I left it at that.

Recently installed Plex on my debian server and tried to play around with some logging and MRTG graphing, mainly to learn some useful grep, awk, wc and cut commands.
For example,

Code: Select all
#!/bin/bash

export LD_LIBRARY_PATH=/usr/lib/plexmediaserver

/usr/lib/plexmediaserver/Plex\ Media\ Scanner -l -c 3 | wc -l > no_songs.txt
echo 0 >> no_songs.txt

Did list number of songs and allowed me to MRTG plot it. There might be a more elegant solution to it, but good enough for me. However, listing all TV shows with
Code: Select all
Plex\ Media\ Scanner -l -c 1

does produce output just like -c 3, but I'm unable to send the output to a file nor pipe it. Since
Code: Select all
Plex\ Media\ Scanner -l -c 3

and
Code: Select all
Plex\ Media\ Scanner -l -c 3 | cat

produces the same output and I can pipe it to a file with >, the same thing would go for -c 1, but no.
Code: Select all
Plex\ Media\ Scanner -l -c 1 | cat
produces no output and
Code: Select all
Plex\ Media\ Scanner -l -c 1 > file
will produce an empty file.

No difference if I create a shell script, pipe the result to a file first or go straight to | wc, tried piping to awk, piping both stdout and stderr with &> or anything similar, the result just disappears when I try to do anything else but show it on screen.

I have never encountered anything similar. What to look for? What could cause this?
winny
 
Posts: 13
Joined: 2013-11-05 11:11

Re: Command produces output, but unable to pipe nor send to

Postby Bloom » 2018-08-26 15:47

It probably outputs to stderr, so if you redirect stderr with '2>' of '2|' it should work.
User avatar
Bloom
 
Posts: 71
Joined: 2017-11-11 12:23

Re: Command produces output, but unable to pipe nor send to

Postby winny » 2018-08-26 17:35

Bloom wrote:It probably outputs to stderr, so if you redirect stderr with '2>' of '2|' it should work.


No difference. Both stdout and errout are empty. :?
winny
 
Posts: 13
Joined: 2013-11-05 11:11

Re: Command produces output, but unable to pipe nor send to

Postby Bloom » 2018-08-28 04:36

What does 'ofile' contain if you do this:

Code: Select all
Plex\ Media\ Scanner -l -c 3 > ofile 2>&1
cat ofile

?
User avatar
Bloom
 
Posts: 71
Joined: 2017-11-11 12:23

Re: Command produces output, but unable to pipe nor send to

Postby winny » 2018-08-29 18:58

Bloom wrote:What does 'ofile' contain if you do this:

Code: Select all
Plex\ Media\ Scanner -l -c 3 > ofile 2>&1
cat ofile

?


It produces a list of all songs.

Code: Select all
Plex\ Media\ Scanner -l -c [b]1[/b] > ofile 2>&1
cat ofile


On the other hand produces an empty file :-(

EDIT: Oh! Can't do bold in line with code. Anyhow, the -c 1 and -c 3 makes all the difference somehow.

EDIT 2: Played around a bit more and

Code: Select all
Plex\ Media\ Scanner -l -c 2

and
Code: Select all
Plex\ Media\ Scanner -l -c 2 | cat

Does in fact not produce the same output. What do you call these non new line feed "errors" were you (bash) prompt does not start on it's own new line but rater directly after a for example cat output? Are there any special characters which can't be piped?
winny
 
Posts: 13
Joined: 2013-11-05 11:11

Re: Command produces output, but unable to pipe nor send to

Postby debiman » 2018-08-30 18:16

winny wrote:What do you call these non new line feed "errors" were you (bash) prompt does not start on it's own new line but rater directly after a for example cat output? Are there any special characters which can't be piped?
that's not an error. it means the output did not end with a carriage return.

all in all it looks like a quirk in this plex utility (executables with spaces in their filenames? really?), and i don't see how the shell can fix anything here.
ask plex developers/forums.
User avatar
debiman
 
Posts: 3017
Joined: 2013-03-12 07:18


Return to Beginners Questions

Who is online

Users browsing this forum: No registered users and 8 guests

fashionable