Is there an easy way to capture the stdout (and stderr) output
of an external command run using (!) without using files?
I'd like to be able to do something like:
(set 'file04 (! "ls -l | grep 2004"))
and have the result be the string spit out by
grep instead of the return code as (!) does now.
Perhaps the set of $ variables could be extended
to include a $stdout and $stderr such that after
running the above $stdout would contain the output
of grep and $stderr would be nil.
Another approach would be to redefine (!) to return
a list containing the result code, stdout, and stderr
as in:
(! "echo 'abc' ") --> ( 0 "abc" nil).
Instead of '!' use 'exec' it captures the standard out in a list line by line, i.e: on Solaris:
Sun Microsystems Inc. SunOS 5.8 Generic February 2000
~> newlisp
newLISP v.8.2.5 Copyright (c) 2004 Lutz Mueller. All rights reserved.
> (exec "ls /etc")
("TIMEZONE" "acct" "aliases" "aliases.dir" "aliases.pag" "ami" "apache"
"asppp.cf" "auto_home" "auto_master" "autopush" "cfgadm" "chroot"
............
"vfstab.orig" "vfstab.s1" "volcopy" "vold.conf" "wall" "whodo" "wtmpx")
>
There are many Unixs commands working well with 'exec' but try also
the function "process" which can redirect std I/O to pipes.
Lutz
Thanks, Lutz.
It would be nice to have "see also (exec)"
in the manual entries for (!) and (process).
I will add those references
Lutz