rouge
rouge copied to clipboard
PowerShell: bracket redirections (>and >> and >&1)
Name of the lexer: powershell.
Code sample A sample of the code that produces the bug.
dir C:\, fakepath 2>&1 > .\dir.log
.\script.ps1 > script.log
&{
Write-Warning "hello"
Write-Error "hello"
Write-Output "hi"
} 3>&1 2>&1 > C:\Temp\redirection.log
.\script.ps1 *> script.log
$ErrorActionPreference = 'Continue'
$ErrorActionPreference > log.txt
get-item /not-here 2>&1 >> log.txt
$ErrorActionPreference = 'SilentlyContinue'
$ErrorActionPreference >> log.txt
get-item /not-here 2>&1 >> log.txt
$ErrorActionPreference = 'Stop'
$ErrorActionPreference >> log.txt
Try {
get-item /not-here 2>&1 >> log.txt
}
catch {
"`tError caught!" >> log.txt
}
$ErrorActionPreference = 'Ignore'
$ErrorActionPreference >> log.txt
get-item /not-here 2>&1 >> log.txt
$ErrorActionPreference = 'Inquire'
$ErrorActionPreference >> log.txt
get-item /not-here 2>&1 >> log.txt
$ErrorActionPreference = 'Continue'
It also helps if you can provide a link to a code sample on rouge.jneen.net -- this doesn't seem to open, I tested it with https://rouge.fly.dev/encode?file_name=8ed1bed8-6f6b-4ea2-90b1-f2c71024d54e.txt&lang=powershell&theme=base16.dark.
Additional context
These code samples are taken from the Microsoft article on redirection, but all the > symbols are marked with a red background (which I'm assuming implies a syntax error).