我正在尝试使用PowerShell(版本2(Start-Process
并重命名新启动的窗口标题。我有以下代码片段可以正常工作,它会启动一个新的 PowerShell 窗口并尾部日志($c
包含要尾部的日志文件(:-
Start-Process powershell.exe -Argument "Get-Content", $c, "-wait"
我不确定如何包含以下内容,以便可以更改新启动的窗口标题。
$host.ui.RawUI.WindowTitle = 'New window title rename example text'
干杯。
"脏"的解决方案是:
start-process powershell.exe -argument "`$host.ui.RawUI.WindowTitle = 'New window title rename example text'; get-content -Path $c -wait"
我建议为您创建一个脚本命令并使用参数进行输入。
无题2.ps1
param($c)
$host.ui.RawUI.WindowTitle = 'New window title rename example text'
Get-Content -Path $c -Wait
脚本
$script = Get-Item ".DesktopUntitled2.ps1"
$c = Get-Item ".Desktopt.txt"
Start-Process powershell.exe -ArgumentList "-File $($script.FullName) -c $($c.FullName)"
一个更干净的 powershell 解决方案,尤其是在生成进程时要运行进一步命令时,可能是这样的。
$StartInfo = new-object System.Diagnostics.ProcessStartInfo
$StartInfo.FileName = "$pshomepowershell.exe"
$StartInfo.Arguments = "-NoExit -Command `$Host.UI.RawUI.WindowTitle=`'Your Title Here`'"
[System.Diagnostics.Process]::Start($StartInfo)
如果有人需要一个简单的方法,你可以在Powershell中尝试一下:
cmd.exe /c "start ""my app"" powershell.exe -NoExit -Command ""dotnet myapp"""
这也意味着 cmd 中的此命令:
start "myapp" powershell.exe -NoExit -Command "dotnet myapp"