如何将参数传递给保存的 SBCL 核心?

发布于 2024-10-17 20:08:51 字数 932 浏览 0 评论 0原文

我有一个 Lisp (SBCL 1.0.40.0.debian) 应用程序 (myfitnessdata),它使用以下代码来处理命令行参数:

(:use :common-lisp)
(:export #:main))

(in-package :myfitnessdata)

(require :sb-posix)

;; snip

(defun main ()
  (if (= (length sb-ext:*posix-argv*) 3)
    (let ((username (nth 0 sb-ext:*posix-argv*))
      (password (nth 1 sb-ext:*posix-argv*))
      (path (nth 2 sb-ext:*posix-argv*)))
      (scrape (username password path)))
    (show-usage)))

我正在使用以下 Lisp 代码编译此应用程序:

(load "myfitnessdata.lisp")
(save-lisp-and-die "myfitnessdata.bin" :executable t :toplevel 'myfitnessdata:main)

这会生成一个我可以运行的可执行文件。但是,sb-ext:*posix-argv* 列表始终为空。如果我运行以下命令:

./myfitnessdata.bin myusername mypassword /home/me/data

...那么我得到的只是 (show-usage) 生成的使用说明。

我想我一定又错过了一些简单的东西 - 有人可以让我知道如何 (save-lisp-and-die) 以便生成的可执行文件采用命令行参数吗?

I have a Lisp (SBCL 1.0.40.0.debian) application (myfitnessdata), which uses the following code to process command line arguments:

(:use :common-lisp)
(:export #:main))

(in-package :myfitnessdata)

(require :sb-posix)

;; snip

(defun main ()
  (if (= (length sb-ext:*posix-argv*) 3)
    (let ((username (nth 0 sb-ext:*posix-argv*))
      (password (nth 1 sb-ext:*posix-argv*))
      (path (nth 2 sb-ext:*posix-argv*)))
      (scrape (username password path)))
    (show-usage)))

I am compiling this application using the following Lisp code:

(load "myfitnessdata.lisp")
(save-lisp-and-die "myfitnessdata.bin" :executable t :toplevel 'myfitnessdata:main)

This produces an executable that I can run. However, the sb-ext:*posix-argv* list is always empty. If I run the following:

./myfitnessdata.bin myusername mypassword /home/me/data

... then all I get is the usage instructions produced by (show-usage).

I think I must be missing something simple again - could someone please let me know how to (save-lisp-and-die) such that the resultant executable takes command line arguments?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那支青花 2024-10-24 20:08:51

正如 sbcl-help 上的好人所建议的解决方案是使用 buildapp 等工具来编译应用程序。您可以指定一个入口点,该入口点被假定为具有一个参数的函数。在运行时,使用命令行参数列表调用该函数。

使用 buildapp,我的 main 函数现在是:

(defun main (args)
  (if (= (length args) 4)
      (let ((username (nth 1 args))
           (password (nth 2 args))
           (path (nth 3 args)))
    (scrape username password path))
    (show-usage)))

The solution, as suggested by the good folks on sbcl-help, is to use a tool like buildapp to compile the app. You can specify an entry point, which is assumed to be a function with one argument. At run-time, that function is called with a list of command-line parameters.

Using buildapp, my main function is now:

(defun main (args)
  (if (= (length args) 4)
      (let ((username (nth 1 args))
           (password (nth 2 args))
           (path (nth 3 args)))
    (scrape username password path))
    (show-usage)))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文