How to capture output from (!) ?

Q&A's, tips, howto's
Locked
gregben
Posts: 20
Joined: Wed Mar 10, 2004 5:00 pm
Location: San Diego, California, USA

How to capture output from (!) ?

Post by gregben »

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).

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

Instead of '!' use 'exec' it captures the standard out in a list line by line, i.e: on Solaris:

Code: Select all

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

gregben
Posts: 20
Joined: Wed Mar 10, 2004 5:00 pm
Location: San Diego, California, USA

Post by gregben »

Thanks, Lutz.

It would be nice to have "see also (exec)"
in the manual entries for (!) and (process).

Lutz
Posts: 5289
Joined: Thu Sep 26, 2002 4:45 pm
Location: Pasadena, California
Contact:

Post by Lutz »

I will add those references

Lutz

Locked