由于某种原因,我无法从命令行/批处理文件调用中正确执行此函数。
function streamMonitor {
[cmdletbinding()]
param(
[string]$directoryPath,
[string]$scriptToRestartPath
)
... the rest of my code
}
在挖掘了大量论坛并询问 chatgpt 后,这里是尝试过的众多方法之一,我相信应该完全有效,但事实并非如此。
Powershell.exe -executionpolicy remotesigned -File C:\pathto\streamMonitor.ps1 -directoryPath "C:\pathto\stream1" -scriptToRestartPath "C:\pathto\stream1.bat"
执行时,终端不会抛出语法错误,但 powershell 脚本也不会运行。
您正在创建一个函数,但没有调用它。这是输出您输入的两个参数的版本。
function streamMonitor {
[cmdletbinding()]
param(
[string]$directoryPath,
[string]$scriptToRestartPath
)
Write-Output $directoryPath
Write-Output $scriptToRestartPath
}
streamMonitor -directoryPath "C:\pathto\stream1" -scriptToRestartPath "C:\pathto\stream1.bat"