2

我有以下脚本来安装 topshelf 服务:

$exePath = "./My.exe"

$service = get-service | Where {$_.Name -eq "MyService"}
if($service -ne $null) {
    Write-Host "Service already installed, will do a reinstall"
    if($service.Status -eq "Running") {
        Write-Host "Stopping service"
        & $exePath stop
    }
    Write-Host "Uninstalling service"
    & $exePath uninstall
}
Write-Host "Installing service"
& $exePath install
Write-Host "Starting service"
& $exePath start

当我运行这个脚本时,我必须在每一步之间按回车键。有没有解决的办法?

4

1 回答 1

0

感谢: Richard Forrest 和 Tomas Jansson:

Console.ReadLine()在控制台应用程序的末尾

ZoolWay 建议:

if ((System.Diagnostics.Debugger.IsAttached) && (Environment.UserInteractive)) Console.ReadLine()

很抱歉在这个答案中使用了其他人的想法,但我认为这需要以 100% 的概率被看到。我会对答案/评论给予与 Richard Forrest 中 R 的数量一样多的支持:

ARRRRRRRRRRRR

于 2019-04-17T20:07:43.273 回答