From: Adam Warner
Subject: Running a shell in CLISP and CMUCL
Date: 
Message-ID: <pan.2002.12.09.02.57.55.376620@consulting.net.nz>
Hi all,

Could you please help me work out how to emulate CLISP's ext:shell
functionality in CMUCL. Here's what I have done in CLISP to generate an
HTML version of an RTF document:

#+clisp (ext:shell (concatenate 'string "unrtf --html ../" file " > index.html"))

I couldn't figure out how to pipe files in CMUCL using the Unix shell
(Bash) so instead I used the built-in Unix run-program support:

#+cmu   (with-open-file (stream "index.html" :direction :output :if-exists :supersede)
          (let* ((process (ext:run-program "unrtf"
                                           (list "--html" (concatenate 'string "../" file))
                                           :output :stream :wait nil))
                 (output (ext:process-output process)))
            (loop for line = (read-line output nil nil) until (eq line nil)
                  do (write-line line stream))
            (ext:process-close process)))

I'd like to know how to perform the same quick-and-dirty one-liner that I
used in CLISP. Tips to the newsgroup so other people can learn these bad
habits as well please.

Thanks,
Adam

From: Eric Marsden
Subject: Re: Running a shell in CLISP and CMUCL
Date: 
Message-ID: <wzik7ija6qh.fsf@melbourne.laas.fr>
>>>>> "aw" == Adam Warner <······@consulting.net.nz> writes:

  aw> Could you please help me work out how to emulate CLISP's ext:shell
  aw> functionality in CMUCL. Here's what I have done in CLISP to generate an
  aw> HTML version of an RTF document:
  aw> 
  aw> #+clisp (ext:shell (concatenate 'string "unrtf --html ../" file " > index.html"))
  aw> 
  aw> I couldn't figure out how to pipe files in CMUCL using the Unix shell
  aw> (Bash) so instead I used the built-in Unix run-program support

since the :output argument to EXT:RUN-PROGRAM accepts a pathname (see
the CMUCL Users' Guide, or the function's docstring), you can simply
say 
  
  (ext:run-program "unrtf" `("--html" ,(concatenate 'string "../" file))
                   :output "index.html")

If you really want to emulate all the quoting and $IFS nightmares and
init file madness of the POSIX system() call, you can use something
like
                   
  (ext:run-program "/bin/sh" '("-c" "--html ../index.html > index.html"))

For real use you should check the exit code of the process, and signal
an error if it is nonzero. 

-- 
Eric Marsden                          <URL:http://www.laas.fr/~emarsden/>
From: Adam Warner
Subject: Re: Running a shell in CLISP and CMUCL
Date: 
Message-ID: <pan.2002.12.09.09.58.01.388504@consulting.net.nz>
Hi Eric Marsden,

>   aw> Could you please help me work out how to emulate CLISP's ext:shell
>   aw> functionality in CMUCL. Here's what I have done in CLISP to generate an
>   aw> HTML version of an RTF document:
>   aw> 
>   aw> #+clisp (ext:shell (concatenate 'string "unrtf --html ../" file " > index.html"))
>   aw> 
>   aw> I couldn't figure out how to pipe files in CMUCL using the Unix shell
>   aw> (Bash) so instead I used the built-in Unix run-program support
> 
> since the :output argument to EXT:RUN-PROGRAM accepts a pathname (see
> the CMUCL Users' Guide, or the function's docstring), you can simply
> say 
>   
>   (ext:run-program "unrtf" `("--html" ,(concatenate 'string "../" file))
>                    :output "index.html")

Thanks. I somehow overlooked that I could simply output to a file instead of a
stream.

> If you really want to emulate all the quoting and $IFS nightmares and
> init file madness of the POSIX system() call, you can use something
> like
>                    
>   (ext:run-program "/bin/sh" '("-c" "--html ../index.html > index.html"))
> 
> For real use you should check the exit code of the process, and signal
> an error if it is nonzero.

Indeed. Thanks again for the tips.

Regards,
Adam