Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
来自windows powershell的Inkscape shell循环_Powershell_Shell_Loops_Svg_Inkscape - Fatal编程技术网

来自windows powershell的Inkscape shell循环

来自windows powershell的Inkscape shell循环,powershell,shell,loops,svg,inkscape,Powershell,Shell,Loops,Svg,Inkscape,我在Windows powershell中编写了一个简单的脚本,在导出之前循环浏览一些SVG文件并对页面区域进行调整。这很有效,但速度相对较慢。因此,我想尝试使用Inkscape的shell模式,但对于如何实现这一点,我完全感到困惑。我尝试过本页中使用的方法,但运气不佳。以下是我的“正在工作但速度缓慢”的脚本,展示了我正在尝试做的事情: $files = Get-ChildItem "C:\temp\SVG Charts" -filter *.svg # Starts a

我在Windows powershell中编写了一个简单的脚本,在导出之前循环浏览一些SVG文件并对页面区域进行调整。这很有效,但速度相对较慢。因此,我想尝试使用Inkscape的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"
     
     # 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来完成这项工作:

# Avoid specifying long file paths in Inkscape commands...
Set-Location -Path 'C:\Temp\SVG Charts'

# Build-up a list of actions to send to Inkscape...
[string]$actions = ''
$files = Get-ChildItem -Filter *.svg
foreach ($f in $files) {
    $actions += "file-open:$($f.Name); export-area-drawing; export-filename:Adjusted_$($f.Name); export-do`r`n"
}

# Ensure to end your list of actions with 'quit', then pipe it to Inkscape...
"$actions`r`nquit" | & "C:\Program Files\Inkscape\bin\inkscape.com" --shell

我希望这个简短的示例会有所帮助。

命令行语法在0.92.5和1.0之间发生了显著变化。因此,不要参考链接到的手册页,该手册页适用于当前版本。相反,请在您的Inkscape安装或位于的Inkscape存储库中找到它(或使用更新的Inkscape版本)。非常感谢,我必须与我们的it团队协商,以更新他们提供给我们的Inkscape版本