3

次の SBCL 特殊コードのように、外部プログラムを実行してその出力を取得する ANSI 標準の方法はないようです。

(defmacro with-input-from-program ((stream program program-args environment)
                               &body body)
"Creates an new process of the specified by PROGRAM using
 PROGRAM-ARGS as a list of the arguments to the program. Binds the
 stream variable to an input stream from which the output of the
 process can be read and executes body as an implicit progn."
#+sbcl
(let ((process (gensym)))
    `(let ((,process (sb-ext::run-program ,program
                                      ,program-args
                                      :output :stream
                                      :environment ,environment
                                      :wait nil)))
   (when ,process
     (unwind-protect
          (let ((,stream (sb-ext:process-output ,process)))
            ,@body)
       (sb-ext:process-wait ,process)
       (sb-ext:process-close ,process))))))

次の CCL コードは、「エラー: 値 # は期待されるタイプではありません (AND CCL::BINARY-STREAM INPUT-STREAM)」を報告します。

 #+clozure
 (let ((process (gensym)))
  `(let ((,process (ccl:run-program "/bin/sh" (list "-c" (namestring ,program))
                                    :input nil :output :stream :error :stream
                                    :wait nil)))
   (when ,process
     (unwind-protect
          (let ((,stream (ccl::external-process-output-stream ,process)))     
            ,@body)
       ;(ccl:process-wait (ccl:process-whostate ,process) nil)
       (close (ccl::external-process-output-stream ,process))
       (close (ccl::external-process-error-stream ,process))))))

私はほとんどCCLを知りません。CCL をサポートするためにこのコードを変更する方法を知りたいですか?

どんな提案でも大歓迎です!

4

2 に答える 2

4

明らかtrivial-shell:shell-commandに、あなたが望むものを正確に許可していません(外部コマンドを同期的に実行し、出力全体を返します)。

CCL を調べることができますrun-program。見る:

于 2012-02-05T12:24:18.693 に答える
1

trivial-shellを使用する必要があります。

自明なシェルは、基盤となるオペレーティング システムへの単純なプラットフォームに依存しないインターフェイスです。

于 2012-02-05T10:29:16.693 に答える