【问题标题】:How to start a console app from powershell in a new window如何在新窗口中从 powershell 启动控制台应用程序
【发布时间】:2014-11-18 01:23:22
【问题描述】:

我的团队开发了一个网站,每个开发人员都有一个在完整 IIS 中运行的本地副本。我们还有一项在 Azure 中运行的生产服务,但对于开发,我们将其封装在控制台应用程序中。如果开发人员需要此服务,他可以通过双击 exe、运行批处理或将 exe 固定到他的 Windows 任务栏来启动控制台应用程序。这会在他的桌面上打开一个控制台窗口并保持运行,直到他选择将其关闭。

我正在编写一个 powershell 脚本,开发人员可以运行该脚本来定期更新我们应用程序的许多部分。

当然,如果此服务在控制台应用程序中运行,它会锁定文件。所以我写了这个脚本的一部分来检查控制台应用程序并停止它(这有效)。

但是,我想重新启动它。但只需调用 exe (& MyService.exe) 即可在 powershell 窗口的上下文中启动应用程序并阻止会话。

如何使 exe 出现在它自己的 Windows 控制台窗口中?

if (Get-Process | ? { $_.Name -eq "SchedulerConsole" }) {
    $schedulerwasrunning = $true
    Write-Host "shutting down SchedulerConsole" -ForegroundColor Yellow
    Stop-Process -Name SchedulerConsole
}

...

if ($schedulerwasrunning) {
    Write-Host "restarting SchedulerConsole" -ForegroundColor Yellow
    & "$workspaceroot\blah\blah\SchedulerConsole.exe"
}

【问题讨论】:

    标签: powershell


    【解决方案1】:

    使用Start-Process 而不是& 运算符。这将在新的控制台窗口中生成应用程序。

    【讨论】:

    • 接受这个答案,因为它在 PowerShell 中看起来更自然
    猜你喜欢
    • 2022-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    • 1970-01-01
    • 2013-03-18
    相关资源
    最近更新 更多