使用PowerShell变量作为Pandoc命令行参数

时间:2020-07-15 12:17:05

标签: string powershell command pandoc

我目前正在尝试将现有的批处理文件(cmd)转换为PowerShell脚本。它的功能之一是定义变量列表,这些变量可用作Pandoc的命令行参数。例如,输入和输出格式:

set settings=-f markdown -t docx

pandoc %settings% "input.md" -o "output.docx"

在使用PowerShell尝试类似方法时,变量似乎被解释为好像在字符串两边加上了引号(“”)。以下命令:

Set-Variable -Name "settings" -Value "-f markdown -t docx"

pandoc $settings "input.md" -o "output.docx"

出现以下错误:

Unknown extension: t docx

此命令(不使用变量)给出相同的错误:

pandoc "-f markdown -t docx" "input.md" -o "output.docx"

从变量中排除-f和-t命令时,该命令有效:

Set-Variable -Name "input" -Value "markdown"
Set-Variable -Name "output" -Value "docx"

pandoc -f $input -t $output "input.md" -o "output.docx"

但是,这违背了我预定义这些设置的目的。我尝试了两件事:

  • 创建一个包含所有Pandoc参数的变量
$command = "-f $input -t $output `"input.md`" -o `"output.docx`""

pandoc $command

哪个会导致相同的错误:

Unknown extension: t  input.md
  • 创建一个包含整个命令的变量
$command = "pandoc -f $input -t $output `"input.md`" -o `"output.docx`""

& $command

结果:

& : The term 'pandoc -f  -t  "input.md" -o "output.docx"' is not recognized as the name of a cmdlet, function, script file, or operable
program.

这些变量是否可以与Pandoc命令一起使用?

0 个答案:

没有答案
相关问题