[英]PowerShell executing exe with arguments
我编写了一个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 Cannot read '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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.