问题描述
我已经在Windows powershell中编写了一个简单的脚本,以循环浏览某些SVG文件并在导出之前对页面区域进行调整。这很好,但是相对较慢。因此,我想尝试使用Inkscape的shell模式,但对于如何使它工作完全感到困惑。我尝试了此页面https://inkscape.org/doc/inkscape-man.html中使用的方法,但是没有运气。这是我的“工作但缓慢”的脚本,用于显示我要执行的操作:
$files = Get-ChildItem "C:\temp\SVG Charts" -filter *.svg
# Starts a FOR loop which runs through each of the files from above
foreach ($f in $files){
# Prepare the name of the outputted file
# So you don't save over the originals
$outfile = $f.DirectoryName + "\Adjusted_" + $f.BaseName + ".svg"
# Run inkscape
# The export-area-drawing command below simply resets the print area of the SVG
inkscape $f.FullName --export-area-drawing --export-plain-svg $outfile
}
以下是我尝试的Shell版本。我认为我的循环结构不正确,需要将inkscape --shell
放在循环之外,但是随后它挂了起来,等待输入。如果我将其放入循环中,则系统会提示我为每次迭代键入quit,然后显示许多红色错误文本,我认为这可能与下一点有关……似乎有几种不同的处理方式编写shell命令,我不知道我是否使用了正确的方法!我正在努力解决最后一点,因为我不知道我是否甚至已经以使用shell的正确方式设置了循环。
$files = Get-ChildItem "C:\temp\SVG Charts" -filter *.svg
# Starts a FOR loop which runs through each of the files from above
foreach ($f in $files){
# Prepare the name of the outputted file
# So you don't save over the originals
$outfile = $f.DirectoryName + "\Adjusted_" + $f.BaseName + ".svg"
# The export-area-drawing command below simply resets the print area of the SVG
inkscape --shell
file-open:$f.FullName; export-area-drawing; export-filename:$outfile; export-do
}
我的问题是:我应该如何构造此Powershell循环以及应该使用哪种语法来运行Shell命令?
我正在运行一个相对较旧的Inkscape版本,毫无疑问它没有帮助:Inkscape 0.92.3
解决方法
根据Moini的建议,请升级您的Inkscape版本。我只能使用最新的Inkscape版本1.0.1来做到这一点:
$myDate = [DateTime]"Jul-16";
'{0:yyyy-MM-dd}' -f $myDate
我希望这个简短的例子对您有所帮助。