How to capture output from (!) ?

Started by gregben, November 02, 2004, 03:01:46 PM

Previous topic - Next topic

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

#1
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

gregben

#2
Thanks, Lutz.



It would be nice to have "see also (exec)"

in the manual entries for (!) and (process).

Lutz

#3
I will add those references



Lutz