[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Pipes and processes, stdin, stdout and stderr
From: |
Christopher Allan Webber |
Subject: |
Pipes and processes, stdin, stdout and stderr |
Date: |
Mon, 13 Apr 2015 19:17:41 -0500 |
Hello all,
Last night I was trying to do the equivalent of this:
bash$ echo "foo" | sha512sum
in guile. But I was unable to find a clear way to do it.
I tried something like:
(let* ((port (open-pipe*
OPEN_BOTH
"sha256sum" "--binary")))
(display "test me\n" port)
(force-output port)
(let ((result (drain-input port)))
(close-port port)
(car (string-split result #\space))))
Unfortunately, this just hangs forever at the drain-input. I get the
same issue if I do (read-line port).
What I expected was that Guile would provide a way to access stdin,
stdout, stderr in a process as separate ports. Python provides an API
more or less like this:
>>> from subprocess import Popen, PIPE
>>> proc = Popen("sha256sum", stdin=PIPE, stdout=PIPE)
>>> proc.stdin.write(b"foo")
3
>>> proc.stdin.close()
>>> proc.stdout.read()
b'2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae -\n'
It looks like in the past there were discussions about doing something
similar:
http://comments.gmane.org/gmane.lisp.guile.user/9300
It might be really nice if there was a way to access stdin, stdout, and
stderr as separate ports. I might be willing to write some code for it,
if someone could point me in the right direction. But I really don't
know where to look.
Is there a way to do this that I don't know?
Thanks for the help!
- Chris
- Pipes and processes, stdin, stdout and stderr,
Christopher Allan Webber <=
- Re: Pipes and processes, stdin, stdout and stderr, Vladimir Zhbanov, 2015/04/14
- Re: Pipes and processes, stdin, stdout and stderr, Thien-Thi Nguyen, 2015/04/16
- Re: Pipes and processes, stdin, stdout and stderr, Mark H Weaver, 2015/04/18