Lime
Lime

Reputation: 13569

Powershell output takes longer to display

Run the following command in both command prompt and powershell.

The first one displays instantaneously in command prompt while it takes a little longer in powershell. What might be the reason that it does this?

type file

Is there a way to change or speed up the default powershell behavior?

I am happy to post a video/gif if needed.

Here is a video I'll post a gif if I can at some point https://vid.me/ZjfA

Upvotes: 1

Views: 1676

Answers (2)

Lime
Lime

Reputation: 13569

First open command prompt then run powershell. Or press Win+r and then type powershell. Next type the run the following

powershell.exe -noexit -File "C:\Users\a\Desktop\test.ps1"

test.ps1

Remove-Item alias:ls
Remove-Item alias:cat
Remove-Item alias:echo
function ls {cmd /c "dir $args"}
function cat {cmd /c "type $args"}
function echo {cmd /c "echo $args"}

Now your commands should appear to be much faster.

Upvotes: 0

TessellatingHeckler
TessellatingHeckler

Reputation: 29023

type in command prompt reads text. In PowerShell, it reads lines of text and constructs .NET arrays containing a string object per line of file.

(Get-Content is slow and slow and slow and slow and slow and slow).

Upvotes: 4

Related Questions