[PATCH] Re: Closing stdin of asynchronous sub processes

"Eric Mangold" <[email protected]> Fri, 8 Apr 2005 04:02:17 +1000 (ChST)
Newsgroups gmane.lisp.librep
Message-ID <[email protected]>
------=_20050408040217_83974
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

So I had a look at the librep source and came up with a patch to
src/unix_processes.c that exposes a "close-process" function. It
just calls the close_process_files C function that was already
present.

My test program below works perfectly once I added a call to
close-process.

Hopefully this can be committed?

-Eric Mangold

> Hello,
>
> I need set the primary X selection from rep (under sawfish) and it seem=
s
> like using the xclip(1) program is the easiest way.
>
> To test outside of sawfish, I run this with rep:
>
> (setq proc (make-process))
> (start-process proc "xclip" "-i") ;;this reads the text to set from std=
in
> (write proc "set selection to this")
>
> OK, that works fine if you just run it with no event-loop. But, if you =
add
> the event loop...
>
> (setq interrupt-mode 'exit) ;; make it so we can C-c out
> (setq proc (make-process))
> (start-process proc "xclip" "-i") ;;this reads the text to set from std=
in
> (write proc "set selection to this")
> (recursive-edit)
>
> Then the xclip program is indeed launched but it never terminates becau=
se
> it's stdin is still waiting for EOF. Apparently in the non-event-loop
> version, the terminating of the rep binary forces the stdin/out/err of
> xclip to be closed, and so xclip goes and does its thing.
>
> So how does one close the stdin (if that is indeed my problem)?
>
> Thanks,
> Eric Mangold
>
>

------=_20050408040217_83974
Content-Type: text/x-patch; name="unix_processes.c.diff"
Content-Disposition: attachment; filename="unix_processes.c.diff"
Content-Transfer-Encoding: quoted-printable

Index: src/unix_processes.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/gnome/librep/src/unix_processes.c,v
retrieving revision 1.79
diff -u -r1.79 unix_processes.c
--- src/unix_processes.c	28 Oct 2003 22:29:39 -0000	1.79
+++ src/unix_processes.c	7 Apr 2005 17:53:11 -0000
@@ -1117,6 +1117,18 @@
 	return rep_mem_error();
 }
=20
+DEFUN("close-process", Fclose_process, Sclose_process, (repv proc), rep_=
Subr1) /*
+::doc:rep.io.processes#close-processes::
+close-processes [PROCESS]
+
+Closes the stdin, stdout, and stderr of the asynchronous process-object =
PROCESS.
+::end:: */
+{
+    rep_DECLARE1(proc, PROCESSP);
+    close_proc_files(VPROC(proc));
+    return(Qnil);=20
+}
+
 DEFUN("start-process", Fstart_process, Sstart_process, (repv arg_list), =
rep_SubrN) /*
 ::doc:rep.io.processes#start-process::
 start-process [PROCESS] [PROGRAM] [ARGS...]
@@ -2072,6 +2084,7 @@
     rep_INTERN(socketpair);
=20
     tem =3D rep_push_structure ("rep.io.processes");
+    rep_ADD_SUBR(Sclose_process);
     rep_ADD_SUBR(Smake_process);
     rep_ADD_SUBR(Sstart_process);
     rep_ADD_SUBR(Scall_process);
------=_20050408040217_83974--



-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click