Emacs呼叫过程偶然发现了提供的ARGS内容
我对呼叫程序通话的意外行为感到困惑。
这是一个小功能:
(defun work-in-progress()
"run ledger report and output result in current buffer.
The intention is to run following command (works perfectly from shell):
`ledger -U csv --sort date --file ledger-file child`
where ledger-file is a known and defined variable.
The problem is that the command fails with:
`Error: Illegal option -`
"
(interactive)
(cd ledger-dir)
(setq child "peter")
(setq parms "-U csv --sort date --file")
(setq prog "ledger") ; should be found via path variable or so
(call-process prog nil t t parms ledger-file child)
)
我已经使用了Ledger命令选项的顺序,但是Emacs似乎总是抱怨PARMS变量中的第一个选项或所有选项:
例如
(setq parms "--sort date -U csv --file")
中的ISO结果
Error: Illegal option --sort date -U csv --file
,ISO
Error: Illegal option -
LEDGER CLI程序并不挑剔参数序列,两个描述的选项序列在命令行中调用Ledger时都可以很好地工作。
这确实使我感到困惑。文档读取
call-process program &optional infile destination display &rest args
并设置为nil,目的地以及显示为t,那么为什么不掌握args varible的内容?
任何帮助,更正和/或建议都将是真诚地赞赏的!
I'm puzzled by unexpected behavior of a call-process call.
Here's a little function:
(defun work-in-progress()
"run ledger report and output result in current buffer.
The intention is to run following command (works perfectly from shell):
`ledger -U csv --sort date --file ledger-file child`
where ledger-file is a known and defined variable.
The problem is that the command fails with:
`Error: Illegal option -`
"
(interactive)
(cd ledger-dir)
(setq child "peter")
(setq parms "-U csv --sort date --file")
(setq prog "ledger") ; should be found via path variable or so
(call-process prog nil t t parms ledger-file child)
)
I've played around with the sequence of the ledger command options, but emacs always seems to complain about the first option or all options in the parms variable:
e.g.
(setq parms "--sort date -U csv --file")
results in
Error: Illegal option --sort date -U csv --file
iso
Error: Illegal option -
The ledger cli program isn't fussy about arguments sequence, both described option sequences work perfectly well when calling ledger at the command line.
This truly puzzles me. The documentation reads
call-process program &optional infile destination display &rest args
and infile is set to nil, destination as well as display are t, so why doesn'it grok the content of args variable?
Any help, correction and/or suggestion would be sincerely appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
列表的尾巴应为字符串序列,每个字符串与一个参数相对应。
您需要
应用
将附加
的结果延续到静态参数列表中,以call-process
。我必须猜测什么
LEDGER-FILEFILE
和Child
是;如果它们不是字符串,则需要将它们转换为字符串。为了简要概括shell如何解析参数,命令行
被转换为字符串数组
(使用lispy符号)并将其作为参数传递给
execlp
。The tail of the list should be a sequence of strings, each corresponding to one argument.
You need
apply
to make the result ofappend
into a continuation of the static list of arguments tocall-process
.I had to guess what
ledger-file
andchild
are; if they are not strings, you need to convert them to strings.To briefly recapitulate how the shell parses arguments, the command line
gets turned into the string array
(to use a Lispy notation) and passed as arguments to
execlp
.解决方案是将每个参数作为单独的字符串传递:
The solution is to pass each parameter as a separate string: