我想编写一个直接打开文件的功能。就像Python代码一样:
os.system("ls")
Run Code Online (Sandbox Code Playgroud)
例如,当我使用此功能(fun_open“/path/to/file”)时,系统将使用默认应用程序打开文件。如果文件是 .txt,请使用 textedit 打开它。
怎样制作呢?
----更新 9/24/2015-----
我的代码是:
(defun open_by_system (dir)
(sb-ext:run-program "/usr/bin/open" (list "-a" "Preview" dir)))
Run Code Online (Sandbox Code Playgroud)
我用它:
CL-USER> (open_by_system "~/Desktop/ML.pdf")
#<SB-IMPL::PROCESS :EXITED 1>
Run Code Online (Sandbox Code Playgroud)
没有其他事情发生
我建议您查看 Quickdocs 上的可用库:
我建议您使用 Quicklisp 上提供的劣质外壳
加载中:
CL-USER> (ql:quickload 'inferior-shell)
To load "inferior-shell":
Load 5 ASDF systems:
alexandria asdf closer-mop named-readtables optima
Install 4 Quicklisp releases:
fare-mop fare-quasiquote fare-utils inferior-shell
; Fetching #<URL "http://beta.quicklisp.org/archive/fare-quasiquote/2015-06-08/fare-quasiquote-20150608-git.tgz">
; 15.08KB
==================================================
15,437 bytes in 0.10 seconds (157.03KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/fare-utils/2015-06-08/fare-utils-20150608-git.tgz">
; 31.51KB
==================================================
32,264 bytes in 0.14 seconds (218.80KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/fare-mop/2015-06-08/fare-mop-20150608-git.tgz">
; 2.67KB
==================================================
2,738 bytes in 0.00 seconds (0.00KB/sec)
; Fetching #<URL "http://beta.quicklisp.org/archive/inferior-shell/2015-06-08/inferior-shell-20150608-git.tgz">
; 12.87KB
==================================================
13,182 bytes in 0.00 seconds (12873.05KB/sec)
; Loading "inferior-shell"
[package fare-utils]..............................
[package fare-stateful]...........................
[package fare-quasiquote].........................
[package fare-mop].............
(INFERIOR-SHELL)
Run Code Online (Sandbox Code Playgroud)
一个简单的示例:
CL-USER> (inferior-shell:run/ss '(echo (1) "2" (+ 3)))
"1 2 3"
NIL
0
Run Code Online (Sandbox Code Playgroud)
带管道的样本:
CL-USER> (inferior-shell:run/ss `(inferior-shell:pipe (echo (+ hel "lo,") world) (tr "hw" "HW") (sed -e "s/$/!/")))
"Hello, World!"
NIL
0
Run Code Online (Sandbox Code Playgroud)