about two-way pipes or threads



Hi there,

I have tried a few things to do what I want. I already asked some questions
on threading, on creating/using pipes, but I just cannot figure it out.

What I want is to have control over another application. I need to write
data to it's stdin and read it's stdout. I figured that using the "lower
level pipes" would be nice here, but they don't work a bit. I get all kind
of weird errors, output is only grabbed after the application has quitted.
It is probably necessary to flush this applications output and/or flush my
own grabbing of that output, but anyway, it didn't work (yet). Also, in
some cases, I get xlib-async errors.

My next step was to try to integrate the application in mine. I.e. I change
main(argc, argv[]); into start_sub();, make a .h file and starting it. This
worked, but blocked my app, so I use threads. But the problem now is that
when the thread is stopped, the thread is not really stopped. I.e., control
doesn't return to the main application cycle. I use two pthread_open()s and
when both of them are finished, the pthread-cycle itself doesn't seem to be
closed (do I need to kill the thread cycle itself too?). It locks the
application and I need to close/restart the application to get back to the
main cycle. Here, I also get xlib-async errors, so this doesn't work
either.

Internet says that xlib-async errors means that xlib is not thread-safe. So
is it safe at all to use threads when I get this error as a result?

Thing is that I also used a write-only-pipe (popen(FILE *something, "w");),
and this worked perfect, with the only problem that the output appeared in
the terminal instead of in the stdin of my main app. For now, this is not a
big problem... It would be easiest if someone knew how to grab this output
into my main apps stdin (so make it a r/w-pipe). Is it possible to combine
these two? So make a read- AND write-pipe? Rather not a lower-level pipe
(since that gives errors).

It would also be nice if someone knew how to flush the output or grab the
output in the lower level pipe while the app is running and/or maybe a
website or even a book with all kind of info on this and why I get all
these errors... Because I'm getting desperate, nothing seems to be the
exact solution to what I'm trying to do.

I'm hoping for a perfect solution or something else that looks like it,

Ronald


-- 
---------------------------------------------------.
--   .-.    | Ronald Bultje                        |
--   /V\    | Running: Linux 2.4.1 and OpenBSD 2.8 |
--  // \\   | E-mail : rbultje ronald bitfreak net |
-- /(   )\  | WWW    : http://ronald.bitfreak.net/ |
--  ^^-^^   |    *** Warning: Unix Addicted ***    |
---------------------------------------------------'





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]