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

Output of exec to stdout

30 views
Skip to first unread message

Cecil Westerhof

unread,
Feb 12, 2018, 7:14:06 AM2/12/18
to
I have the following command:
exec youtube-dl -f ${format} -o %(title)s-%(id)s.%(ext)s ${link}

I would like to have the from the youtube-dl command going to the
console. How could I do that?

--
Cecil Westerhof
Senior Software Engineer
LinkedIn: http://www.linkedin.com/in/cecilwesterhof

Gerald Lester

unread,
Feb 12, 2018, 7:16:31 AM2/12/18
to
On 02/12/2018 06:02 AM, Cecil Westerhof wrote:
> I have the following command:
> exec youtube-dl -f ${format} -o %(title)s-%(id)s.%(ext)s ${link}
>
> I would like to have the from the youtube-dl command going to the
> console. How could I do that?
>

See the answers to your post on "Output from a pipe in a scroll-able
window", but instead of inserting into a text widget, use [puts stdout]
to write it to the console.


--
+----------------------------------------------------------------------+
| Gerald W. Lester, President, KNG Consulting LLC |
| Email: Gerald...@kng-consulting.net |
+----------------------------------------------------------------------+

Rich

unread,
Feb 12, 2018, 7:23:31 AM2/12/18
to
Cecil Westerhof <Ce...@decebal.nl> wrote:
> I have the following command:
> exec youtube-dl -f ${format} -o %(title)s-%(id)s.%(ext)s ${link}
>
> I would like to have the from the youtube-dl command going to the
> console. How could I do that?

What OS?

If Linux, just use exec's redirect option to redirect stdout to
/dev/stdout (and start your program from a xterm, rxvt, or other
terminal).

If Windows, well, you've got some work to do in that case.

Cecil Westerhof

unread,
Feb 12, 2018, 7:44:05 AM2/12/18
to
Cecil Westerhof <Ce...@decebal.nl> writes:

> I have the following command:
> exec youtube-dl -f ${format} -o %(title)s-%(id)s.%(ext)s ${link}
>
> I would like to have the from the youtube-dl command going to the
> console. How could I do that?

I found a reasonable way. Instead of using exec, I use the following:
set fetch [open "|youtube-dl -f ${format} -o %(title)s-%(id)s.%(ext)s ${link}" RDONLY]
while {-1 != [gets ${fetch} line]} {
puts ${line}
}
close ${fetch}

Five lines instead of one and it displays all the download progress
lines on a new line, but for the moment I can live with that.

At the moment I am going to put it in an GUI that is not a problem and
maybe even preferred. ;-)

Cecil Westerhof

unread,
Feb 12, 2018, 8:44:06 AM2/12/18
to
Rich <ri...@example.invalid> writes:

> Cecil Westerhof <Ce...@decebal.nl> wrote:
>> I have the following command:
>> exec youtube-dl -f ${format} -o %(title)s-%(id)s.%(ext)s ${link}
>>
>> I would like to have the from the youtube-dl command going to the
>> console. How could I do that?
>
> What OS?

In my case Linux, but I like to write code that is system independent.


> If Linux, just use exec's redirect option to redirect stdout to
> /dev/stdout (and start your program from a xterm, rxvt, or other
> terminal).

Of-course. I should have thought about that.


> If Windows, well, you've got some work to do in that case.

I already found a reasonable solution. The nice thing about this one
is that I can put the output also in a logging database.

Cecil Westerhof

unread,
Feb 12, 2018, 8:44:06 AM2/12/18
to
Cecil Westerhof <Ce...@decebal.nl> writes:

> Cecil Westerhof <Ce...@decebal.nl> writes:
>
>> I have the following command:
>> exec youtube-dl -f ${format} -o %(title)s-%(id)s.%(ext)s ${link}
>>
>> I would like to have the from the youtube-dl command going to the
>> console. How could I do that?
>
> I found a reasonable way. Instead of using exec, I use the following:
> set fetch [open "|youtube-dl -f ${format} -o %(title)s-%(id)s.%(ext)s ${link}" RDONLY]
> while {-1 != [gets ${fetch} line]} {
> puts ${line}
> }
> close ${fetch}
>
> Five lines instead of one and it displays all the download progress
> lines on a new line, but for the moment I can live with that.

Solved it for Linux:
set fetch [open "|youtube-dl -f ${format} -o %(title)s-%(id)s.%(ext)s ${link}" RDONLY]
while {-1 != [gets ${fetch} line]} {
if {${line} == ""} {
break
}
puts ${line}
}
while {-1 != [gets ${fetch} line]} {
puts -nonewline [format "\r%-80s" ${line}]
flush stdout
}
puts ""
close ${fetch}

Is there a tcl way to put the cursor back to the start of the line, so
I can make it OS independent?

Ralf Fassel

unread,
Feb 12, 2018, 9:22:28 AM2/12/18
to
* Cecil Westerhof <Ce...@decebal.nl>
| Cecil Westerhof <Ce...@decebal.nl> writes:
>
| > I have the following command:
| > exec youtube-dl -f ${format} -o %(title)s-%(id)s.%(ext)s ${link}
| >
| > I would like to have the from the youtube-dl command going to the
| > console. How could I do that?
>
| I found a reasonable way. Instead of using exec, I use the following:
| set fetch [open "|youtube-dl -f ${format} -o %(title)s-%(id)s.%(ext)s ${link}" RDONLY]
| while {-1 != [gets ${fetch} line]} {
| puts ${line}
| }

If 'puts' works, you might as well do

exec youtube-dl -f ${format} -o %(title)s-%(id)s.%(ext)s ${link} >@stdout 2>@stderr &

This redirection from TCL might fail on Windows when there is no
stdout/stderr open.

HTH
R'

Rich

unread,
Feb 12, 2018, 11:53:34 AM2/12/18
to
Cecil Westerhof <Ce...@decebal.nl> wrote:
> Is there a tcl way to put the cursor back to the start of the line,
> so I can make it OS independent?

This depends upon the terminal under which it is running.

The closest you can get from plain tcl is a -nonewline puts with a \r
where you want the cursor to return to the start of a line.

And, whether a \r, when output, actually does return to the start of a
line is terminal (configuration) dependent (i.e., if your terminal were
set to interpret \r as if it were \n, you'd get plural lines anyway).

0 new messages