在程序文件中使用 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 Files7-Zip7z.exe"
The variables being fed into $command are already set and $SevenZip is "c:Program Files7-Zip7z.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 Files7-zip7z.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屋!