unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* How to read a string output with `open-input-pipe` on Mac OS?
@ 2023-10-10  0:49 Panisuan Chasinga
  2023-10-10  4:31 ` tomas
  2023-10-10 10:41 ` Zelphir Kaltstahl
  0 siblings, 2 replies; 5+ messages in thread
From: Panisuan Chasinga @ 2023-10-10  0:49 UTC (permalink / raw)
  To: guile-user

Hi list, I want to read a string output using `ice-9/popen/open-input-pipe`
but somehow always got an empty string. Here is my test code:


(use-modules (ice-9 popen))
(use-modules (ice-9 textual-ports))

(define (test-read-port)
  (let* ((port (open-input-pipe "ls"))
           (str (get-string-all p)))
     (close-port p)
     str))


I was able to read from a file with `open-input-file`, but not
`open-input-pipe` with any command. Running `(system "ls")` seemed to work
just fine.


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to read a string output with `open-input-pipe` on Mac OS?
  2023-10-10  0:49 Panisuan Chasinga
@ 2023-10-10  4:31 ` tomas
  2023-10-10 10:41 ` Zelphir Kaltstahl
  1 sibling, 0 replies; 5+ messages in thread
From: tomas @ 2023-10-10  4:31 UTC (permalink / raw)
  To: guile-user

[-- Attachment #1: Type: text/plain, Size: 555 bytes --]

On Mon, Oct 09, 2023 at 05:49:09PM -0700, Panisuan Chasinga wrote:
> Hi list, I want to read a string output using `ice-9/popen/open-input-pipe`
> but somehow always got an empty string. Here is my test code:
> 
> 
> (use-modules (ice-9 popen))
> (use-modules (ice-9 textual-ports))
> 
> (define (test-read-port)
>   (let* ((port (open-input-pipe "ls"))
>            (str (get-string-all p)))
>      (close-port p)
>      str))

I guess you have a typo there: when opening, your port is called `port',
later you use `p'.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to read a string output with `open-input-pipe` on Mac OS?
  2023-10-10  0:49 Panisuan Chasinga
  2023-10-10  4:31 ` tomas
@ 2023-10-10 10:41 ` Zelphir Kaltstahl
  2023-10-10 23:07   ` Panisuan Chasinga
  1 sibling, 1 reply; 5+ messages in thread
From: Zelphir Kaltstahl @ 2023-10-10 10:41 UTC (permalink / raw)
  To: Panisuan Chasinga; +Cc: Guile User

On 10/10/23 02:49, Panisuan Chasinga wrote:
> Hi list, I want to read a string output using `ice-9/popen/open-input-pipe`
> but somehow always got an empty string. Here is my test code:
>
>
> (use-modules (ice-9 popen))
> (use-modules (ice-9 textual-ports))
>
> (define (test-read-port)
>    (let* ((port (open-input-pipe "ls"))
>             (str (get-string-all p)))
>       (close-port p)
>       str))
>
>
> I was able to read from a file with `open-input-file`, but not
> `open-input-pipe` with any command. Running `(system "ls")` seemed to work
> just fine.

Hello Panisuan,

perhaps this code can help you as well: 
https://notabug.org/ZelphirKaltstahl/guile-examples/src/22bf7be3ae46a7b520c1482ab80985bfbdae6eb6/input-output/stdout-stderr.scm

It handles also error output.

Best regards,
Zelphir

-- 
repositories: https://notabug.org/ZelphirKaltstahl




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to read a string output with `open-input-pipe` on Mac OS?
  2023-10-10 10:41 ` Zelphir Kaltstahl
@ 2023-10-10 23:07   ` Panisuan Chasinga
  0 siblings, 0 replies; 5+ messages in thread
From: Panisuan Chasinga @ 2023-10-10 23:07 UTC (permalink / raw)
  To: Zelphir Kaltstahl; +Cc: Guile User

Thanks for sharing the code. However, after running the function on any
command like `ls` or `date`, the function only returns two #<eof>. I got an
#<eof> too with this code:

 (define (test-read)
   (let* ((p (open-input-pipe "ls"))
             (str (read-delimited "" p)))
     (close-port p)
     str))

(test-read)

I'm now almost positive this might be a Mac OS-related bug.




On Tue, Oct 10, 2023 at 3:41 AM Zelphir Kaltstahl <
zelphirkaltstahl@posteo.de> wrote:

> On 10/10/23 02:49, Panisuan Chasinga wrote:
> > Hi list, I want to read a string output using
> `ice-9/popen/open-input-pipe`
> > but somehow always got an empty string. Here is my test code:
> >
> >
> > (use-modules (ice-9 popen))
> > (use-modules (ice-9 textual-ports))
> >
> > (define (test-read-port)
> >    (let* ((port (open-input-pipe "ls"))
> >             (str (get-string-all p)))
> >       (close-port p)
> >       str))
> >
> >
> > I was able to read from a file with `open-input-file`, but not
> > `open-input-pipe` with any command. Running `(system "ls")` seemed to
> work
> > just fine.
>
> Hello Panisuan,
>
> perhaps this code can help you as well:
>
> https://notabug.org/ZelphirKaltstahl/guile-examples/src/22bf7be3ae46a7b520c1482ab80985bfbdae6eb6/input-output/stdout-stderr.scm
>
> It handles also error output.
>
> Best regards,
> Zelphir
>
> --
> repositories: https://notabug.org/ZelphirKaltstahl
>
>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: How to read a string output with `open-input-pipe` on Mac OS?
       [not found] <FA53E38F-EED0-463E-9A51-BF07AAB5718C@fil.org>
@ 2023-10-11  4:21 ` tomas
  0 siblings, 0 replies; 5+ messages in thread
From: tomas @ 2023-10-11  4:21 UTC (permalink / raw)
  To: Pan Chasinga; +Cc: Guile User

[-- Attachment #1: Type: text/plain, Size: 231 bytes --]

On Tue, Oct 10, 2023 at 03:27:32PM -0700, Pan Chasinga wrote:
> Excuse my typo but yes the original code doesn’t have a typo and it runs perfectly. Just returns an empty string.

I see, sorry for the noise.

Cheers
-- 
t

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2023-10-11  4:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
     [not found] <FA53E38F-EED0-463E-9A51-BF07AAB5718C@fil.org>
2023-10-11  4:21 ` How to read a string output with `open-input-pipe` on Mac OS? tomas
2023-10-10  0:49 Panisuan Chasinga
2023-10-10  4:31 ` tomas
2023-10-10 10:41 ` Zelphir Kaltstahl
2023-10-10 23:07   ` Panisuan Chasinga

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).