Scheduled Maintenance: We are aware of an issue with Google, AOL, and Yahoo services as email providers which are blocking new registrations. We are trying to fix the issue and we have several internal and external support tickets in process to resolve the issue. Please see: viewtopic.php?t=158230

 

 

 

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

New to Debian (Or Linux in general)? Ask your questions here!
Post Reply
Message
Author
winny
Posts: 13
Joined: 2013-11-05 11:11

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

#1 Post by winny »

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?

User avatar
Bloom
df -h | grep > 90TiB
df -h | grep > 90TiB
Posts: 504
Joined: 2017-11-11 12:23
Been thanked: 26 times

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

#2 Post by Bloom »

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

winny
Posts: 13
Joined: 2013-11-05 11:11

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

#3 Post by winny »

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. :?

User avatar
Bloom
df -h | grep > 90TiB
df -h | grep > 90TiB
Posts: 504
Joined: 2017-11-11 12:23
Been thanked: 26 times

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

#4 Post by Bloom »

What does 'ofile' contain if you do this:

Code: Select all

Plex\ Media\ Scanner -l -c 3 > ofile 2>&1
cat ofile
?

winny
Posts: 13
Joined: 2013-11-05 11:11

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

#5 Post by winny »

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?

User avatar
debiman
Posts: 3063
Joined: 2013-03-12 07:18

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

#6 Post by debiman »

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.

Post Reply