This is the mail archive of the
guile@sources.redhat.com
mailing list for the Guile project.
Re: system call: how to get access to results ?
- To: David Pirotte <david at altosw dot be>, guile-user at gnu dot org
- Subject: Re: system call: how to get access to results ?
- From: "Dale P. Smith" <dpsm at en dot com>
- Date: Sat, 16 Sep 2000 11:21:53 -0400
- List-Id: <guile-user.gnu.org>
- Organization: Altus Technologies Corporation.
- References: <39C3744D.9FAB4309@altosw.be>
David Pirotte wrote:
>
> Hello,
>
> I have defined the following very simple function, to get access
> to the system date:
>
> (define (system-date . rest)
> (if (null? rest)
> (system "date '+%d-%m-%Y'")
> (system (format #f "date ~A" (car rest)))))
>
> However, I don't know how I can get access to the result, when sending
> a date string and expecting a result, such as:
>
> (system-date (format #f "--date='~A' '+%w'" "09/15/2000")
> 5
> 0
>
> The system "displays" the result, but returned value is the exit code
>
> How can I "get access" to the expected returned value ?
How about the popen module? Something like (pardon my lame code):
(use-modules (ice-9 popen))
(define (system-date . rest)
(let ((p (open-input-pipe (if (null? rest)
"date '+%d-%m-%Y'"
(format #f "date ~A" (car rest))))))
(let ((line (read-line p)))
(close-pipe p)
line)))
(display (system-date))
16-09-2000
(display (system-date ""))
Sat Sep 16 11:22:52 EDT 2000
Although I would probably use something like:
(strftime "%d-%m-%Y" (localtime (current-time)))
-Dale
--
Dale P. Smith
Altus Technologies Corp.
dsmith@altustech.com
400-746-9000 x309
_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user