Skip to content

System.ArgumentOutOfRangeException when running multi-line Python command in PowerShellΒ #4958

@Devansh503

Description

@Devansh503

Prerequisites

  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues, especially the pinned issues.

Exception report

Exception:
System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: top
Actual value was -2.
   at System.Console.SetCursorPosition(Int32 left, Int32 top)
   at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
   at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
   at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
   at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable`1 key, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary`2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
   at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
   at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)
-----------------------------------------------------------------------

Screenshot


Last 200 Keys:
] Enter
Enter
f o r Space m o d u l e _ p a t h , Space n a m e Space i n Space p r o j e c t _ m o d u l e s : Enter
Space Space Space Space t r y : Enter
Space Space Space Space Space Space Space Space _ _ i m p o r t _ _ ( m o d u l e _ p a t h ) Enter
Space Space Space Space Space Space Space Space p r i n t ( f ' √ Space { n a m e } : Space O K ' ) Enter
Space Space Space Space e x c e p t Space I m p o r t E r r o r Space a s Space e : Enter
Space Space Space Space Space Space Space Space p r i n t ( f ' ? Space { n a m e } : Space F A I L E D Space - Space { e } ' ) Enter
" Space } Enter
Alt+1 Alt+2 & Space " . \ . v

Exception:
System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: top
Actual value was -2.
at System.Console.SetCursorPosition(Int32 left, Int32 top)
at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
at Microsoft.PowerShell.PSConsoleReadLine.SelfInsert(Nullable1 key, Object arg) at Microsoft.PowerShell.PSConsoleReadLine.ProcessOneKey(ConsoleKeyInfo key, Dictionary2 dispatchTable, Boolean ignoreIfNoAction, Object arg)
at Microsoft.PowerShell.PSConsoleReadLine.InputLoop()
at Microsoft.PowerShell.PSConsoleReadLine.ReadLine(Runspace runspace, EngineIntrinsics engineIntrinsics)

Environment data

PS Version: 5.1.19041.6328
PS HostName: ConsoleHost
PSReadLine Version: 2.0.0-beta2
PSReadLine EditMode: Windows
OS: 10.0.19041.1 (WinBuild.160101.0800)
BufferWidth: 150
BufferHeight: 41

Steps to reproduce

Open PowerShell or Windows Terminal.

Activate a Python virtual environment:

..venv\Scripts\activate

Run this multi-line inline Python command:

& "..venv\Scripts\python.exe" -c "
import sys
print('Python version:', sys.version)
print('\n--- Testing Critical Dependencies ---')

packages_to_test = [
('fastapi', 'FastAPI'),
('uvicorn', 'Uvicorn'),
('streamlit', 'Streamlit'),
('torch', 'PyTorch'),
('transformers', 'Transformers'),
('sklearn', 'Scikit-learn'),
('pandas', 'Pandas'),
('numpy', 'NumPy'),
('nltk', 'NLTK'),
('datasets', 'HuggingFace Datasets')
]

for package, name in packages_to_test:
try:
module = import(package)
version = getattr(module, 'version', 'Unknown')
print(f'√ {name}: {version}')
except ImportError as e:
print(f'? {name}: FAILED - {e}')
"

PowerShell crashes or throws an exception before execution completes, showing an error from PSReadLine:

System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: top
Actual value was -1.

Expected behavior

The command should execute the inline Python script normally and print dependency check results without any interruption or crash.

Actual behavior

PowerShell crashes with the following PSReadLine error:

System.ArgumentOutOfRangeException: The value must be greater than or equal to zero and less than the console's buffer size in that dimension.
Parameter name: top
Actual value was -1.
at System.Console.SetCursorPosition(Int32 left, Int32 top)
at Microsoft.PowerShell.PSConsoleReadLine.ReallyRender(RenderData renderData, String defaultColor)
at Microsoft.PowerShell.PSConsoleReadLine.ForceRender()
at Microsoft.PowerShell.PSConsoleReadLine.Insert(Char c)
...

This occurs consistently when pasting or editing long multi-line commands that exceed the PowerShell buffer or line wrapping region.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions