Lisp HUG Maillist Archive

Calling unix functions from Lispworks

Hello everybody,

Does somebody knows how can I call unix functions from Lisp and get the output ?
For example:

(print (calling-from-lispworks "ls  /Users/etc/etc"))

::> ". .. a/ b/ c/ ... etc"

I am using Lispworks Professional 5.0 and Mac OS X 10.5.2.

Thanks,

Mauricio

--
Mauricio Toro Bermudez
Estudiante de Ingeniería de Sistemas
Pontificia Universidad Javeriana, Colombia

Stagiare à l'Ircam
1, place Igor-Stravinsky 75004 Paris,
France de 2008 à 2009

Re: {Disarmed} Calling unix functions from Lispworks

"Mauricio Toro" <mauriciotorob@gmail.com> writes:

> 1.  ( ) text/plain          (*) text/html           
>
> Hello everybody,
>
> Does somebody knows how can I call unix functions from Lisp and get the output
> ?

See system:open-pipe, system:call-system and
system:call-system-showing-output - they are documented in the
reference manual (but not in the user guide, I think, so it's not so
obvious).

-- 
  (espen)


Re: {Disarmed} Calling unix functions from Lispworks

that works. Thanks.
Is it portable?
Or that is just for Lispworks?

2008/8/11 Espen Vestre <ev@netfonds.no>
"Mauricio Toro" <mauriciotorob@gmail.com> writes:

> 1.  ( ) text/plain          (*) text/html
>
> Hello everybody,
>
> Does somebody knows how can I call unix functions from Lisp and get the output
> ?

See system:open-pipe, system:call-system and
system:call-system-showing-output - they are documented in the
reference manual (but not in the user guide, I think, so it's not so
obvious).

--
 (espen)



--
Mauricio Toro Bermudez
Estudiante de Ingeniería de Sistemas
Pontificia Universidad Javeriana, Colombia

Stagiare à l'Ircam
1, place Igor-Stravinsky 75004 Paris,
France de 2008 à 2009

Re: {Disarmed} Calling unix functions from Lispworks

"Mauricio Toro" <mauriciotorob@gmail.com> writes:

> that works. Thanks.
> Is it portable?
> Or that is just for Lispworks?

It's not portable, but there are portable libraries which use
open-pipe (e.g. port-shell.lisp in clocc).
-- 
  (espen)


Re: {Disarmed} Calling unix functions from Lispworks

"Chun Tian (binghe)" <binghe.lisp@gmail.com> writes:

> Another choice:
>
> asdf:run-shell-command

That will run call-system-showing-output, which may or may not be what
you want (if you want to parse the output of the shell command, you
need to use open-pipe).

-- 
  (espen)


Re: {Disarmed} Calling unix functions from Lispworks

Espen Vestre <ev@netfonds.no> writes:

> That will run call-system-showing-output, which may or may not be what
> you want (if you want to parse the output of the shell command, you
> need to use open-pipe).

Not necessarily.  You can wrap call-system-showing-output in
(with-output-to-string (*standard-output*) ...)

-- 
Mvh/Regards
Peder O. Klingenberg
Netfonds Bank ASA


Re: {Disarmed} Calling unix functions from Lispworks

Hello again,

I still have one little problem.
How can I know the current path where I am working on?
for example "/Users/me/Desktop" and how can I change
this path.

The problem arises when I do something like
(system:call-system-showing-output "ls")

it always execute the shell command in the root directory ("/") and I do not
know how to change it.

Thanks for all,

Mauricio

2008/8/11 Peder O. Klingenberg <pok@netfonds.no>
Espen Vestre <ev@netfonds.no> writes:

> That will run call-system-showing-output, which may or may not be what
> you want (if you want to parse the output of the shell command, you
> need to use open-pipe).

Not necessarily.  You can wrap call-system-showing-output in
(with-output-to-string (*standard-output*) ...)

--
Mvh/Regards
Peder O. Klingenberg
Netfonds Bank ASA



--
Mauricio Toro Bermudez
Estudiante de Ingeniería de Sistemas
Pontificia Universidad Javeriana, Colombia

Stagiare à l'Ircam
1, place Igor-Stravinsky 75004 Paris,
France de 2008 à 2009

Re: Calling unix functions from Lispworks

On Mon, Aug 11, 2008 at 6:14 AM, Mauricio Toro <mauriciotorob@gmail.com> wrote:
> Hello everybody,
> Does somebody knows how can I call unix functions from Lisp and get the
> output ?
> For example:
> (print (calling-from-lispworks "ls  /Users/etc/etc"))
> ::> ". .. a/ b/ c/ ... etc"
> I am using Lispworks Professional 5.0 and Mac OS X 10.5.2.
> Thanks,
> Mauricio

There are a number of ways. You'd probably be interested in

CALL-SYSTEM
http://www.lispworks.com/documentation/lw51/LWRM/html/lwref-650.htm

OPEN-PIPE
http://www.lispworks.com/documentation/lw51/LWRM/html/lwref-734.htm#15712

CALL-SYSTEM-SHOWING-OUTPUT
http://www.lispworks.com/documentation/lw51/LWRM/html/lwref-651.htm#20692

RUN-SHELL-COMMAND
http://www.lispworks.com/documentation/lw51/LWRM/html/lwref-742.htm#31535

Those are doc pages for CALL-SYSTEM and the function's in
CALL-SYSTEM's "See Also" section. Hope this helps,

//JT


Re: {Disarmed} Calling unix functions from Lispworks

I didn't know about HCL:GET-WORKING-DIRECTORY (but now I do, thanks!),
but there's also SYSTEM:CURRENT-DIRECTORY which is exported, but
doesn't seem to be documented (I only just realized that now).
However, it has the useful feature that it takes an optional
relative-directory:

CL-USER 11 > (sys:current-directory)
#P"/Users/tayloj/"

CL-USER 12 > (sys:current-directory #P"subdirectory1/subdirectory2/")
#P"/Users/tayloj/subdirectory1/subdirectory2/"

//JT

On Mon, Aug 11, 2008 at 8:45 AM, Chun Tian (binghe)
<binghe.lisp@gmail.com> wrote:
> HCL:GET-WORKING-DIRECTORY:
> http://www.lispworks.com/documentation/lw51/LWRM/html/lwref-219.htm#pgfId-889197
> There're 3 important packages in LispWorks: HCL (Harlequin-Common-Lisp),
> SYSTEM, and LISPWORKS, if you read LW Reference Manual about functions in
> these packages, you'll find many useful utlilities. But these functions are
> not portable, if you focus in writing portable CL applications, you should
> not use them, try other portable packages.
> --binghe
> 在 2008-8-11,下午8:37, Mauricio Toro 写道:
>
> Hello again,
> I still have one little problem.
> How can I know the current path where I am working on?
> for example "/Users/me/Desktop" and how can I change
> this path.
> The problem arises when I do something like
> (system:call-system-showing-output "ls")
> it always execute the shell command in the root directory ("/") and I do not
> know how to change it.
> Thanks for all,
> Mauricio
> 2008/8/11 Peder O. Klingenberg <pok@netfonds.no>
>>
>> Espen Vestre <ev@netfonds.no> writes:
>>
>> > That will run call-system-showing-output, which may or may not be what
>> > you want (if you want to parse the output of the shell command, you
>> > need to use open-pipe).
>>
>> Not necessarily.  You can wrap call-system-showing-output in
>> (with-output-to-string (*standard-output*) ...)
>>
>> --
>> Mvh/Regards
>> Peder O. Klingenberg
>> Netfonds Bank ASA
>
>
>
> --
> Mauricio Toro Bermudez
> Estudiante de Ingeniería de Sistemas
> Pontificia Universidad Javeriana, Colombia
>
> Stagiare à l'Ircam
> 1, place Igor-Stravinsky 75004 Paris,
> France de 2008 à 2009
>
>



-- 
=====================
Joshua Taylor
tayloj@cs.rpi.edu, jtaylor@alum.rpi.edu

"A lot of good things went down one time,
 back in the goodle days."
 John Hartford
Updated at: 2020-12-10 08:42 UTC