我正在尝试从控制台运行一个Racket文件作为部署的一部分。部分原因是使用pandoc编译文件。我有一个命令可以直接从控制台调用它,但是当我从Racket中调用它时它不起作用。
成功的命令:
pandoc example.md -H pandoc.css
这给了我一个关于我应该如何在HTML文件中包含标题的警告,但是它会向stdout发出一些HTML。
Racket代码进行三次调用,并为每次调用显示输出到stdout和stderr。它有点笨重,因此代码将位于底部。在这里,我只是将它所做的调用和输出。
> /bin/ls ./
> /usr/bin/pandoc example.md
> /usr/bin/pandoc example.md -H pandoc.css
来自前两个的标准:
example.md
pandoc.css
pandoc.rkt
<h1 id="first-section">First Section</h1>
<p>This is an example markdown file.</p>
stderr for third:
pandoc: example.md -H pandoc.css: openBinaryFile: does not exist (No such file or directory)
任何线索,为什么它可以找到example.md
,但它找不到pandoc.css
?
这是pandoc.rkt的完整代码。这是我第一次在Racket中使用端口,所以如果我以一种可怕的方式做某事,请随时告诉我。
#lang racket
(define-values (ls out1 in1 err1)
(subprocess #f #f #f "/bin/ls" "./"))
(subprocess-wait ls)
(define files (port->lines out1))
(define error (port->lines err1))
(display files) (display "\n")
(display error) (display "\n")
(close-input-port out1)
(close-output-port in1)
(close-input-port err1)
(define-values (pandoc out2 in2 err2)
(subprocess #f #f #f "/usr/bin/pandoc" "example.md"))
(subprocess-wait pandoc)
(define html (port->lines out2))
(set! error (port->lines err2))
(display html) (display "\n")
(display error) (display "\n")
(close-input-port out2)
(close-output-port in2)
(close-input-port err2)
(set!-values (pandoc out2 in2 err2)
(subprocess #f #f #f "/usr/bin/pandoc" "example.md -H pandoc.css"))
(subprocess-wait pandoc)
(set! html (port->lines out2))
(set! error (port->lines err2))
(display html) (display "\n")
(display error) (display "\n")
(close-input-port out2)
(close-output-port in2)
(close-input-port err2)
有几个论点:example.md
,-H
和pandoc.css
。因此,你应该根据documentation将它们分开。
也就是说,而不是:
(subprocess #f #f #f "/usr/bin/pandoc" "example.md -H pandoc.css")
使用:
(subprocess #f #f #f "/usr/bin/pandoc" "example.md" "-H" "pandoc.css")
请注意,对于其他几种语言的subprocess
也是如此(例如,Python)。