Emulating pipes

G

Guest

Does anyone know of a way I can make a program read/write from
stdin/stdout so that I can chain it with other commands and
interact with it from python? Unfortunately it's third party
software and thus can't be changed to do so. The program has
to be invoked 'program input.file output.file'. I would like
to do something like 'otherprog | program stdin stdout |
anotherprog' to take advantage of of the multiprocessor
environment I'm on.

I looked at the pipes module and it's really nice.
Unfortunately it breaks the command up and writes temp files
to overcome this, so it won't use multiple processes.

Any suggestions would be greatly appreciated.
I'm running Python 2.2.3 on a 24 processor IRIX64 6.5.14f.

Thanks,
Brian
 
C

Christopher T King

Does anyone know of a way I can make a program read/write from
stdin/stdout so that I can chain it with other commands and interact
with it from python?
I would like to do something like 'otherprog | program stdin stdout |
anotherprog' to take advantage of of the multiprocessor environment I'm
on.

There are a few command-line solutions to this problem:

IRIX may or may not provide the /dev/stdin and /dev/stdout devices. These
were introduced (?) by Linux as a means to access the current process's
stdin and stdout file descriptors, respectively:

$ otherprog | program /dev/stdin /dev/stdout | anotherprog

If IRIX doesn't provide this, and you are using bash (or something based
on it), you could use process substitution. This is a magic construction
that allows you to use programs where files are expected:

$ program <(otherprog) >(anotherprog)

If that fails, your last resort is to use named FIFOs (this is one way
process substitution is implemented, the other being similar to the
first solution):

$ mkfifo tmpfifo1
$ mkfifo tmpfifo2
$ otherprog > tmpfifo1 & program tmpfifo1 tmpfifo2 & anotherprog < tmpfifo2

Hope this helps.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,202
Messages
2,571,057
Members
47,665
Latest member
salkete

Latest Threads

Top