powershell - 如何在Powershell中永远重复一个命令?

标签 powershell

我正在运行一个我想在它完成后重新运行的命令,而无需导航回终端再次输入该命令。

我知道在 Ubuntu 中,我可以使用命令运行终端,如果我设置正确,它将永远循环,例如 gnome-terminal -x $MY_COMMAND .

鉴于我无法将 Powershell 标记为重新运行命令而不是关闭窗口,我如何无限期地重复命令?

最佳答案

这将在执行完成后无限重复运行命令:

While (1)
{
    Start-Process -FilePath 'python3' -ArgumentList @('.\manage.py','runserver_plus','8080') -Wait -ErrorAction 'SilentlyContinue'
}

或者:
#requires -Version 3
While (1)
{
    Try {
        $Params = @{FilePath='python3'
                    ArgumentList=@('.\manage.py','runserver_plus','8080')
                    Wait=$True
                    ErrorAction='Stop'}
        Start-Process @Params
    } Catch {
        <# Deal with errors #>
        Continue
    }
}

关于powershell - 如何在Powershell中永远重复一个命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46182207/

相关文章:

powershell - 忽略 Powershell 字符串中的通配符 []

powershell - 仅当存在另一个开关时才允许开关参数

git - 为什么在 powershell 和 posh git 中没有黄色

windows - 在文件名中使用通配符的 Invoke-WebRequest -OutFile <filename>

powershell - 如何通过 PowerShell 为 Azure Web App 配置 TLS 相互身份验证?

powershell - 如何在Powershell中合并两个列表的每个元素

powershell - 如何更改 Add-Blob Azure cmdlet 的超时值?

powershell - 如何更新 Windows 最新托管运行程序的 github 操作工作流文件中的 PATH

powershell - 从命令行运行 PowerShell ISE?

powershell - 安装 TFS PowerShell Cmdlet