Code to reproduce
main.rs
fn main() {
clearscreen::clear().unwrap();
}
Cargo.toml
[dependencies]
clearscreen = { git = "https://github.com/watchexec/clearscreen", rev = "3e1b4254f881c03b0d290a4066fc38265f2ac064" }
The error
←[H←[2J←[3Jthread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Io(Os { code: 87, kind: InvalidInput, message: "The parameter is incorrect." })', src\main.rs:2:26
Doesn't matter if launch from VSCode console, cmd
or powershell
.
Faulty code, according to debugger: win::is_windows_10
returns true
while the platform is windows 7. This is because the logic inside the function expects pwsh_package_management
to be indicator of windows 10, but it wasn't in my situation. I have no idea when and what software installed this package during windows lifetime. This caused further code to execute SetConsoleMode
on stdout with flag ENABLE_VIRTUAL_TERMINAL_PROCESSING
, which is absent on platforms below windows 10 build number 10586 according to this comment on stackoverflow. As a debugging measure, removing pwsh_package_management
check gets rid of the error on all tested terminals.
Additional information
c:\>systeminfo | findstr /B /C:"OS Name" /C:"OS Version"
OS Name: Microsoft Windows 7 Ultimate
OS Version: 6.1.7601 Service Pack 1 Build 7601
c:\>powershell.exe -Command Get-Command -Module PackageManagement
c:\>echo %ERRORLEVEL%
0