powershell - PowerShell 执行带有参数的 exe
问题描述
我编写了一个 PowerShell 脚本来执行带有空格的参数的 exe,但它一直失败,没有读取完整路径。
$now = Get-Date -format "MM_dd_yyyy"
$onepath ="C:\Program Files (x86)\GoFileRoom\IWMUploadDocuments\logs\"
$scpath = "F:\Program Files\NSClient++\scripts\"
$onefile = "IWMUploadDocumentsLog$now.txt"
$script = "check_log3.exe"
& "$scpath$script" -p "Error Logging into GFR" -l "$onepath$onefile" -c 1
Write-Output "$onepath$onefile"
这是输出:
PS C:\Windows\system32> F:\Program Files\NSClient++\scripts\onesource.ps1 无法读取“C:\Program” C:\Program Files (x86)\GoFileRoom\IWMUploadDocuments\logs\IWMUploadDocumentsLog10_22_2018.txt
解决方案
在我看来,您需要在参数的参数周围加上一组额外的引号-l
:
& "$scpath$script" -p "Error Logging into GFR" -l "`"$onepath$onefile`"" -c 1
或者尝试喷溅论点:
$params = '-p', 'Error Logging into GFR',
'-l', "$onepath$onefile",
'-c', 1
& "$scpath$script" @params
推荐阅读
- python - DataFrame(Flask)中的链接
- iframe - Electron - 绕过同源中的 X-Frame 选项
- google-apps-script - Google Analytics API 教程问题
- c# - 在 Powershell 中打开加密密钥不在 C# 中
- sql - 通过连接表进行排序和计数的 SELECT
- nginx - Nginx $connections_active 每个服务器块
- c - 为什么我的第二个子进程在我的第一个子进程之前被击中?
- ios - iOS PDFKit 没有填充 UIView
- python - 有没有办法将 yaml 转换为数据框?或者以某种方式展平或规范化许多呈现为 JSON 的数据集?
- endianness - little endian 如何处理 ASCII 字符串?