我正在尝试使用PowerShell(版本2)Start-Process并重命名新启动的窗口标题。我的以下代码段运行良好,它启动了一个新的PowerShell窗口并尾部记录了日志($c包含尾部的日志文件):-
Start-Process powershell.exe -Argument "Get-Content", $c, "-wait"
Run Code Online (Sandbox Code Playgroud)
我不确定如何添加以下内容,以便可以更改新启动的窗口标题。
$host.ui.RawUI.WindowTitle = 'New window title rename example text'
Run Code Online (Sandbox Code Playgroud)
干杯。
一个更简洁的 powershell 解决方案,尤其是当您要在生成进程时运行更多命令时,可能是这样的。
$StartInfo = new-object System.Diagnostics.ProcessStartInfo
$StartInfo.FileName = "$pshome\powershell.exe"
$StartInfo.Arguments = "-NoExit -Command `$Host.UI.RawUI.WindowTitle=`'Your Title Here`'"
[System.Diagnostics.Process]::Start($StartInfo)
Run Code Online (Sandbox Code Playgroud)
一个“肮脏”的解决方案是:
start-process powershell.exe -argument "`$host.ui.RawUI.WindowTitle = 'New window title rename example text'; get-content -Path $c -wait"
Run Code Online (Sandbox Code Playgroud)
我建议为您的命令创建一个脚本,并使用参数进行输入。
Untitled2.ps1
param($c)
$host.ui.RawUI.WindowTitle = 'New window title rename example text'
Get-Content -Path $c -Wait
Run Code Online (Sandbox Code Playgroud)
脚本
$script = Get-Item ".\Desktop\Untitled2.ps1"
$c = Get-Item ".\Desktop\t.txt"
Start-Process powershell.exe -ArgumentList "-File $($script.FullName) -c $($c.FullName)"
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4907 次 |
| 最近记录: |