How to start interaction with executed program?

How to start interaction with executed program?

Post by Arjen Mark » Sat, 11 Feb 2006 20:48:05


Something like:

proc run {..} {
- Open a pipe to the program
- Register a read and a write script via fileevent
# Wait for a variable that will be set when the pipe closes
vwait closed
return $retcode
}

All the details are on the Wiki - look for fileevent
Regards,

Arjen
 
 
 

How to start interaction with executed program?

Post by Sektor van » Sat, 11 Feb 2006 22:36:48

Dnia 10 Feb 2006 03:48:05 -0800, Arjen Markus skrobie:


Good. How to open a pipe so that it considers putting thru all three channels:
stdin, stdout, stderr?

The only examples I can see about opening a pipe are read-only and write-only.
If even it is possible to open pipe for both reading and writing, I still
don't know, what about stderr.

Same thing is in perl (there is something like Pipe3, I remember something
like that...) and same thing is in unix function popen.

Yes, I need some simple "pipe3" function to implment that. Using that I am
able to register fileevent handlers for all of the three separately.


--
// _ ___ Michal "Sektor" Malecki <sektor(whirl)kis.p.lodz.pl>
\\ L_ |/ `| /^\ ,() <ethourhs(O)wp.pl>
// \_ |\ \/ \_/ /\ C++ bez cholesterolu: http://www.yqcomputer.com/ ~sektor/cbx
"I am allergic to Java because programming in Java reminds me casting spells"

 
 
 

How to start interaction with executed program?

Post by Arjen Mark » Sat, 11 Feb 2006 23:11:57

Hm, I am not sure, but I think the "readable" script will catch both
stdout and stderr
from the external process. If you open the pipe with "w+" access you
can read
from and write to the other process.

Other than that: there is nothing like a small experiment :)
Regards,

Arjen
 
 
 

How to start interaction with executed program?

Post by Uwe Klei » Sat, 11 Feb 2006 23:27:37


> Hm, I am not sure, but I think the "readable" script will catch both
> stdout and stderr
> from the external process. If you open the pipe with "w+" access you
> can read
> from and write to the other process.
>
> Other than that: there is nothing like a small experiment :)
> Regards,
>
> Arjen
>

When you are finished with experimenting/testing you might be
interested in comparing your solution to "expect"

uwe
 
 
 

How to start interaction with executed program?

Post by Arjen Mark » Sun, 12 Feb 2006 00:03:41

Yes, expect might be a much better solution than something homebrewn.

Regards,

Arjen
 
 
 

How to start interaction with executed program?

Post by Sektor van » Sun, 12 Feb 2006 01:03:54

Dnia Fri, 10 Feb 2006 15:27:37 +0100, Uwe Klein skrobie:

Of course, I used expect for that before. However using expect I need to read
from the input buffer somehow. Can fileevent be used also for expect's pipe?

--
// _ ___ Michal "Sektor" Malecki <sektor(whirl)kis.p.lodz.pl>
\\ L_ |/ `| /^\ ,() <ethourhs(O)wp.pl>
// \_ |\ \/ \_/ /\ C++ bez cholesterolu: http://www.yqcomputer.com/ ~sektor/cbx
"I am allergic to Java because programming in Java reminds me casting spells"
 
 
 

How to start interaction with executed program?

Post by Sektor van » Sun, 12 Feb 2006 01:10:57

Dnia 10 Feb 2006 06:11:57 -0800, Arjen Markus skrobie:


I'm gonna experiment, but only when there is some reasonable solution. This
one you gave here is good, but not perfect. If my script has to be occupied
with redirecting pipe's channels to natural std* channels, there has to be
also some means to make a difference between stdout and stderr. If I open one
pipe for both reading and writing, I must know, what channel was some text
written to.

I'd like to have a generic solution. If I use it, for example, inside my
script to produce some results that will be redirected from stdout, I need
that the text written to stderr (by the underling process) be filtered out.


--
// _ ___ Michal "Sektor" Malecki <sektor(whirl)kis.p.lodz.pl>
\\ L_ |/ `| /^\ ,() <ethourhs(O)wp.pl>
// \_ |\ \/ \_/ /\ C++ bez cholesterolu: http://www.yqcomputer.com/ ~sektor/cbx
"I am allergic to Java because programming in Java reminds me casting spells"
 
 
 

How to start interaction with executed program?

Post by Uwe Klei » Sun, 12 Feb 2006 01:25:42


Hnn?
hope it stays readable:

<-- send_user exp_send -->
<user> <expect> <your candidate>
exp_user --> expect --<
expect_background --<

<>------------------------interact--------------------<>


expect_background can be useful ( like [expect] but runs in background
like fileevent, does not know about timeouts )

uwe