栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Common Lisp:使用与Lisp进程不同的工作目录启动子进程

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Common Lisp:使用与Lisp进程不同的工作目录启动子进程

要运行外部程序(如可移植的python进程),请参阅external-program。要更改当前的工作目录,请使用

cwd
文件http://files.b9.com/lboot/utils.lisp中经过稍微修改的(公共领域)功能,该功能在下面复制。

(defun cwd (&optional dir)  "Change directory and set default pathname"  (cond   ((not (null dir))    (when (and (typep dir 'logical-pathname)(translate-logical-pathname dir))      (setq dir (translate-logical-pathname dir)))    (when (stringp dir)      (setq dir (parse-namestring dir)))    #+allegro (excl:chdir dir)    #+clisp (#+lisp=cl ext:cd #-lisp=cl lisp:cd dir)    #+(or cmu scl) (setf (ext:default-directory) dir)    #+cormanlisp (ccl:set-current-directory dir)    #+(and mcl (not openmcl)) (ccl:set-mac-default-directory dir)    #+openmcl (ccl:cwd dir)    #+gcl (si:chdir dir)    #+lispworks (hcl:change-directory dir)    #+sbcl (sb-posix:chdir dir)    (setq cl:*default-pathname-defaults* dir))   (t    (let ((dir       #+allegro (excl:current-directory)       #+clisp (#+lisp=cl ext:default-directory #-lisp=cl lisp:default-directory)       #+(or cmu scl) (ext:default-directory)       #+sbcl (sb-unix:posix-getcwd/)       #+cormanlisp (ccl:get-current-directory)       #+lispworks (hcl:get-working-directory)       #+mcl (ccl:mac-default-directory)       #-(or allegro clisp cmu scl cormanlisp mcl sbcl lispworks) (truename ".")))      (when (stringp dir)    (setq dir (parse-namestring dir)))      dir))))

结合这两个功能,所需的代码是:

(cwd #p"../b/")(external-program:start "python" '("file.py") :output *pythins-stdout-stream* :input *pythons-stdin-stream*)(cwd #p"../a/")

这将

cd
到B,像运行by一样运行python进程
python file.py &
,将python进程的stdin /
stdout发送到指定的流(
external-program
有关更多详细信息,请参见文档),最后执行另一个
cwd
将Lisp进程返回给A的操作。应该等到python进程完成后,使用
external-program:run
代替
external-program:start



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/429206.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号