Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PowerShell: bracket redirections (>and >> and >&1) #2089

Open
danya02 opened this issue Nov 26, 2024 · 0 comments
Open

PowerShell: bracket redirections (>and >> and >&1) #2089

danya02 opened this issue Nov 26, 2024 · 0 comments
Labels
bugfix-request A request for a bugfix to be developed.

Comments

@danya02
Copy link

danya02 commented Nov 26, 2024

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).

изображение

@danya02 danya02 added the bugfix-request A request for a bugfix to be developed. label Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix-request A request for a bugfix to be developed.
Projects
None yet
Development

No branches or pull requests

1 participant