Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Output of exec-ed program still shows on stdout

35 views
Skip to first unread message

Johannes Linkels

unread,
Apr 17, 2018, 8:41:30 PM4/17/18
to
Debian Jessie
Tcl version 8.6
Bash 4.3.30
Kernel 3.16.0-4-amd64


I am lost as far as it concerns output redirection. And about the actual command passed to the shell as well.

This is the Tcl code:
dict set station ppid [exec /usr/bin/mplayer -novideo -dumpstream $uri -dumpfile $fn </dev/null &>/dev/null &]

As far as I can see with &>/dev/null I redirect all output to /dev/null. But when I run the Tcl application I still see the song title and number of bytes written as output of my Tcl program.

Only when I run tclsh myprogram.tcl > /dev/null the output disappears.

However, when I execute mplayer directly in the shell, no output is visible. It seems that the output of mplayer is first sent back the the tcl application and then /dev/null is considered.

Likewise, when I omit "< /dev/null" in the exec call, mplayer does not run. When I run mplayer on the command line without "< /dev/null" it runs fine.

And this is what I see using ps:
/usr/bin/mplayer -novideo -dumpstream http://194.232.200.147:8000 -dumpfile /home/jlinkels/.mp_radio/orf_salzburg_1524008156-1524008156.mp3 &>/dev/null

So my input redirection has disappeared. The output redirector is still there, but mplayer's output is still passed back into its parent.

According to this article http://wiki.tcl.tk/1039 redirection should work just fine.

Where is my lack of understanding?

jlinkels

Ralf Fassel

unread,
Apr 18, 2018, 4:22:39 AM4/18/18
to
* Johannes Linkels <jlink...@gmail.com>
| Debian Jessie
| Tcl version 8.6
| Bash 4.3.30
| Kernel 3.16.0-4-amd64
>
| I am lost as far as it concerns output redirection. And about the
| actual command passed to the shell as well.
>
| This is the Tcl code:
| dict set station ppid [exec /usr/bin/mplayer -novideo -dumpstream $uri -dumpfile $fn </dev/null &>/dev/null &]
| As far as I can see with &>/dev/null I redirect all output to
| /dev/null. But when I run the Tcl application I still see the song
| title and number of bytes written as output of my Tcl program.

https://www.tcl.tk/man/tcl/TclCmd/exec.htm
and specifically https://www.tcl.tk/man/tcl/TclCmd/exec.htm#M15

mention only ">&" as redirection of both stdout and stderr, not "&>"
(IIRC "&>" is a bash idiom).

| And this is what I see using ps:
| /usr/bin/mplayer -novideo -dumpstream http://194.232.200.147:8000 -dumpfile /home/jlinkels/.mp_radio/orf_salzburg_1524008156-1524008156.mp3 &>/dev/null
>
| So my input redirection has disappeared. The output redirector is
| still there, but mplayer's output is still passed back into its parent.

Quite the opposite: input redirection *is* in place (recognized by TCL
and *not* passed as command line argument), but the output redirection
was not recognized by TCL as such and passed as command line argument to
mplayer instead.

=> Try >& instead of &> for redirection.

HTH
R'

Johannes Linkels

unread,
Apr 18, 2018, 11:39:43 AM4/18/18
to
> Quite the opposite: input redirection *is* in place (recognized by TCL
> and *not* passed as command line argument), but the output redirection
> was not recognized by TCL as such and passed as command line argument to
> mplayer instead.
>
> => Try >& instead of &> for redirection.
>
> HTH
> R'

Well.... this was easy to overlook. I have read through the man page a dozen times, even just before I posted the question.

And yes, you are right. Redirection is working now as expected, and also the redirection qualifier is recognized by Tcl and not passed to mplayer. It does not show up in ps either so that is also correct.

Thanks for sharing your insight.

jlinkels
0 new messages