newLISP Fan Club

Forum => newLISP in the real world => Topic started by: gregben on November 02, 2004, 03:01:46 PM

Title: How to capture output from (!) ?
Post by: gregben on November 02, 2004, 03:01:46 PM
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).
Title:
Post by: Lutz on November 02, 2004, 04:25:00 PM
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
Title:
Post by: gregben on November 02, 2004, 04:35:19 PM
Thanks, Lutz.



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

in the manual entries for (!) and (process).
Title:
Post by: Lutz on November 02, 2004, 04:50:15 PM
I will add those references



Lutz