检查相同的 powershell 脚本是否已经 运行ning 和 运行 如果是,稍后再检查
Check if the same powershell script is already running and run it later if yes
我正在通过远程服务器上的 ssh (apache) Powershell 脚本从我的 Java EE 应用程序调用,该脚本不能 运行 并行,所以我需要检查脚本是否已经 运行ning 并等待直到没有进程和 运行 等待脚本。脚本可能会被调用多次,例如。几秒钟内 20 次,所有这些都需要 运行 一个接一个。
知道这是如何实现的,或者这是否可能?谢谢!
我在我的一些脚本中完成此操作的方法是使用锁定文件
$lockFile = "$PSScriptRoot\LOCK"
if (-not (Test-Path $lockFile)) {
New-Item -ItemType File -Path $lockFile | Out-Null
# Do other stuff...
Remove-Item -Path $lockFile -Force
}
你可以修改成这样吗?
$lockFile = "$PSScriptRoot\LOCK"
while (Test-Path $lockFile)
{
Start-Sleep -Seconds 2
}
New-Item -ItemType File -Path $lockFile | Out-Null
# Do other stuff...
Remove-Item -Path $lockFile -Force
我正在通过远程服务器上的 ssh (apache) Powershell 脚本从我的 Java EE 应用程序调用,该脚本不能 运行 并行,所以我需要检查脚本是否已经 运行ning 并等待直到没有进程和 运行 等待脚本。脚本可能会被调用多次,例如。几秒钟内 20 次,所有这些都需要 运行 一个接一个。
知道这是如何实现的,或者这是否可能?谢谢!
我在我的一些脚本中完成此操作的方法是使用锁定文件
$lockFile = "$PSScriptRoot\LOCK"
if (-not (Test-Path $lockFile)) {
New-Item -ItemType File -Path $lockFile | Out-Null
# Do other stuff...
Remove-Item -Path $lockFile -Force
}
你可以修改成这样吗?
$lockFile = "$PSScriptRoot\LOCK"
while (Test-Path $lockFile)
{
Start-Sleep -Seconds 2
}
New-Item -ItemType File -Path $lockFile | Out-Null
# Do other stuff...
Remove-Item -Path $lockFile -Force