Google Groepen ondersteunt geen nieuwe Usenet-berichten of -abonnementen meer. Historische content blijft zichtbaar.

Output from a pipe in a scroll-able window

37 weergaven
Naar het eerste ongelezen bericht

Cecil Westerhof

ongelezen,
12 feb 2018, 05:28:0512-02-2018
aan
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

ongelezen,
12 feb 2018, 06:02:2412-02-2018
aan
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

ongelezen,
12 feb 2018, 06:36:0212-02-2018
aan
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

ongelezen,
12 feb 2018, 07:14:2012-02-2018
aan
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

ongelezen,
12 feb 2018, 07:44:0512-02-2018
aan
I will look at it. Thanks.

Cecil Westerhof

ongelezen,
12 feb 2018, 08:14:0612-02-2018
aan
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

ongelezen,
12 feb 2018, 11:48:5712-02-2018
aan
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

ongelezen,
12 feb 2018, 16:50:4112-02-2018
aan
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 nieuwe berichten