chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Controlling output of processes


From: Thomas Chust
Subject: Re: [Chicken-users] Controlling output of processes
Date: Fri, 12 Mar 2010 21:26:47 +0100

2010/3/12 Lasse Kliemann <address@hidden>:
> How can I start a process and control where it sends its stdout
> or stderr? I know that I can do:
>
> (receive
>   (p-stdout p-stdin p-pid p-stderr)
>   (process* command args)
>   (...))
>
> This gives input and output ports connected to the process. But
> how can I express, e.g.: "everything available on port p-stdout
> should go to (current-output-port)"?
> [...]

Hello Lasse,

if you do not want to redirect input and output from the process but
use the same standard input and output as your calling program, just
use process-run instead of process or process*.

However, if you want to redirect input or output of an external
process from or to some arbitrary Scheme port you have the problem
that on the operating system level, the input and output streams
of processes are represented by file handles not Scheme port objects
and there is no one to one correspondence between these two
things. Therefore your best option is indeed to fork the process with
redirection and copy data between the ports connected to the process
and the sources or targets you intend to use. You can perform the copy
operations on separate threads to preserve the order of I/O operations
approximately.

Only if the Scheme ports you intend to use as sources or targets do
correspond to file descriptors, you can hack something up using
port->fileno, process-fork, duplicate-fileno and process-execute. But
such a solution will probably only work on real operating systems,
ie. those following the POSIX standard, not on WinDOS ;-)

Ciao,
Thomas


-- 
When C++ is your hammer, every problem looks like your thumb.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]