程序文件中带有exe的调用表达 [英] Invoke-Expression with exe in Program Files
问题描述
我正在尝试运行Powershell命令以使用以下命令调用7-Zip压缩文件夹:
I'm trying to run a Powershell command to call 7-Zip to zip up a folder using the following command:
$command = $SevenZip + " a " + $targetDirForZip + $GetDateName + "_" + $dir.Name + ".7z " + $dir.FullName
Invoke-Expression $command
输入到$ command中的变量已经设置,并且$ SevenZip是 c:\Program Files\7-Zip\ \7z.exe
The variables being fed into $command are already set and $SevenZip is "c:\Program Files\7-Zip\7z.exe"
这不起作用,我正在尝试找出从Powershell调用7-Zip的最佳方法。
This isn't working and I'm trying to work out the best way to call 7-Zip from Powershell. Ideas?
推荐答案
我以前遇到过同样的问题。这是我目前使用的备份脚本的代码(几乎):
I've had the same problem before. This is code (almost) straight from a backup script that I use currently:
[string]$pathToZipExe = "C:\Program Files\7-zip\7z.exe";
[Array]$arguments = "a", "-tgzip", $outputFilePath, $inputFilePath;
& $pathToZipExe $arguments;
我已经习惯在调用运算符中使用参数数组,这似乎是比其他方法更强大。
I've gotten into the habit of using an argument array with the call operator, It seems to be more robust than other methods.
这篇关于程序文件中带有exe的调用表达的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!