[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Chicken-users] with-pipe in POSIX
From: |
Alejandro Forero Cuervo |
Subject: |
[Chicken-users] with-pipe in POSIX |
Date: |
Mon, 28 Feb 2005 22:39:36 -0500 |
User-agent: |
Mutt/1.5.6+20040907i |
Hi.
I have noticed with-input-from-pipe and with-output-to-pipe. Is there
a more generic function that allows my procedure to communicate with
the command through both its input and output file descriptors?
For example, I need my process to run a ssh command and then talk with
it in both directions: write information to the command and read
information from the command.
Is this possible? I haven't found a function to do this.
Would a general with-pipe function be feasible?
Currently I'm using the following code:
; -- start --
(declare (foreign-declare
#<<EOF
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdlib.h>
EOF
))
(define fork-run-real
(foreign-lambda*
scheme-object
((c-string cmd))
#<<EOF
pid_t son_pid;
int sp[2];
socketpair(PF_UNIX, SOCK_STREAM, 0, sp);
son_pid = fork();
if (son_pid == 0)
{
dup2(sp[0], 0);
dup2(sp[0], 1);
system(cmd);
close(sp[0]);
exit(0);
}
return(C_fix(sp[1]));
EOF
))
(define (fork-run cmd)
(let ((fd (fork-run-real cmd)))
(values (open-input-file* fd) (open-output-file* fd))))
; -- end --
Shouldn't a with-pipe function be included (specially since
with-input-from-pipe and with-output-to-pipe are) in the POSIX unix?
Thanks!
Alejo.
http://bachue.com/alejo
---=( Comunidad de Usuarios de Software Libre en Colombia )=---
---=( http://bachue.com/colibri )=--=( address@hidden )=---
signature.asc
Description: Digital signature