简体   繁体   English

如何更快地批量运行 powershell 命令?

[英]How to make running powershell commands in batch faster?

You can create coloured text in the command prompt, but when it runs it's really slow.您可以在命令提示符中创建彩色文本,但是当它运行时它真的很慢。 Is there any way of making it faster?有没有办法让它更快?

My Code:我的代码:

@echo off
cls
powershell write-host -fore Yellow -back Red "Merry" -NoNewLine
powershell write-host -fore Red -back Yellow "Christmas" -NoNewLine
powershell write-host -fore Yellow -back Red "To" -NoNewLine
powershell write-host -fore Red -back Yellow "Everyone" -NoNewLine
powershell write-host -fore Yellow -back Red "In" -NoNewLine
powershell write-host -fore Red -back Yellow "2020!" -NoNewLine

Powershell is an external program, that has to be loaded each time it is used. Powershell是一个外部程序,每次使用都要加载。 So use it just once:所以只使用一次:

@echo off
cls
powershell write-host -fore Yellow -back Red "Merry" -NoNewLine; ^
write-host -fore Red -back Yellow "Christmas" -NoNewLine;^
write-host -fore Yellow -back Red "To" -NoNewLine;^
write-host -fore Red -back Yellow "Everyone" -NoNewLine;^
write-host -fore Yellow -back Red "In" -NoNewLine;^
write-host -fore Red -back Yellow "2020!" -NoNewLine

Powershell has to be loaded just once compared to 6 times before.与之前的 6 次相比,Powershell 只需加载一次。

The ^ at the end of the lines is a "Line continuation", so actually, this is just one long (logical) line, splitted into several (physical) lines for readabilty:行末尾的^是“行延续”,所以实际上,这只是一个长(逻辑)行,为了可读性分成几行(物理):

powershell write-host -fore Yellow -back Red "Merry" -NoNewLine;write-host -fore Red -back Yellow "Christmas" -NoNewLine;write-host -fore Yellow -back Red "To" -NoNewLine;write-host -fore Red -back Yellow "Everyone" -NoNewLine;write-host -fore Yellow -back Red "In" -NoNewLine;write-host -fore Red -back Yellow "2020!" -NoNewLine

Note, cmd has a maximal line length (about ~8k chars), which limits this method.请注意, cmd具有最大行长度(大约 8k 个字符),这限制了此方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM