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

Output from a pipe in a scroll-able window

37 views
Skip to first unread message

Cecil Westerhof

unread,
Feb 12, 2018, 5:28:05 AM2/12/18
to
I am thinking about writing a GUI around some command-line commands.
Is there a way to put the output from a pipe command into a
scroll-able window?

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

Arjen Markus

unread,
Feb 12, 2018, 6:02:24 AM2/12/18
to
One way is shown in: http://wiki.tcl.tk/3543.

The secret is the [fileevent] command - this allows you to interact with an external process.

Regards,

Arjen

Rich

unread,
Feb 12, 2018, 6:36:02 AM2/12/18
to
Cecil Westerhof <Ce...@decebal.nl> wrote:
> I am thinking about writing a GUI around some command-line commands.
> Is there a way to put the output from a pipe command into a
> scroll-able window?

Look into either the "fileevent" or "chan event ..." commands in the
manual pages ("chan event" appeared somewhere during the 8.5 series,
both hook to the same sub-system).

You'd setup a "filevent" on stdin, and let the event loop handle things
from then on.

Gerald Lester

unread,
Feb 12, 2018, 7:14:20 AM2/12/18
to
On 02/12/2018 04:26 AM, Cecil Westerhof wrote:
> I am thinking about writing a GUI around some command-line commands.
> Is there a way to put the output from a pipe command into a
> scroll-able window?

Yes, read the following man/help/documentation:
From Tcl:
- open (pay attention to the section on pipes "|")
- fileevent (or chan event)
- maybe fconfigure
- read (read not gets)

From Tk:
- text widget
- either scrollbar or ttk::scrollbar


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

Cecil Westerhof

unread,
Feb 12, 2018, 7:44:05 AM2/12/18
to
I will look at it. Thanks.

Cecil Westerhof

unread,
Feb 12, 2018, 8:14:06 AM2/12/18
to
Gerald Lester <Gerald...@KnG-Consulting.net> writes:

> On 02/12/2018 04:26 AM, Cecil Westerhof wrote:
>> I am thinking about writing a GUI around some command-line commands.
>> Is there a way to put the output from a pipe command into a
>> scroll-able window?
>
> Yes, read the following man/help/documentation:
> From Tcl:
> - open (pay attention to the section on pipes "|")
> - fileevent (or chan event)
> - maybe fconfigure
> - read (read not gets)

Why read not gets?
For getting the output from an exec displayed in the console (so no
GUI) I replaced the exec with an open, gets, puts and close. It seems
to work.


> From Tk:
> - text widget
> - either scrollbar or ttk::scrollbar

--

Rich

unread,
Feb 12, 2018, 11:48:57 AM2/12/18
to
Cecil Westerhof <Ce...@decebal.nl> wrote:
> Gerald Lester <Gerald...@KnG-Consulting.net> writes:
>
>> On 02/12/2018 04:26 AM, Cecil Westerhof wrote:
>>> I am thinking about writing a GUI around some command-line commands.
>>> Is there a way to put the output from a pipe command into a
>>> scroll-able window?
>>
>> Yes, read the following man/help/documentation:
>> From Tcl:
>> - open (pay attention to the section on pipes "|")
>> - fileevent (or chan event)
>> - maybe fconfigure
>> - read (read not gets)
>
> Why read not gets?

'gets' always reads a full line (including when running in non-blocking
event driven mode).

The choice depends upon what you really want to do. For what it
sounded like you wanted to do at the outset, either input command is
likely to work just fine for you.

Rich

unread,
Feb 12, 2018, 4:50:41 PM2/12/18
to
Cecil Westerhof <Ce...@decebal.nl> wrote:
> Gerald Lester <Gerald...@KnG-Consulting.net> writes:
>
>> On 02/12/2018 04:26 AM, Cecil Westerhof wrote:
>>> I am thinking about writing a GUI around some command-line commands.
>>> Is there a way to put the output from a pipe command into a
>>> scroll-able window?
>>
>> Yes, read the following man/help/documentation:
>> From Tcl:
>> - open (pay attention to the section on pipes "|")
>> - fileevent (or chan event)
>> - maybe fconfigure
>> - read (read not gets)
>
> Why read not gets?

There is one other reason for 'read' vs. gets I forgot to mention.

'read' lets you control how much data you consume at a time. 'gets'
will continue absorbing data until it finds a line terminator (or runs
out of memory).

So if you were to expose a 'gets' based input to malicious actors, they
can generate an out-of-memory situation for you by feeding your input
with a huge amount of data with no line terminators.

0 new messages