简体   繁体   English

Powershell脚本可在显示时动态替换控制台中的文本

[英]Powershell script to dynamically replace text in console as it is displayed

Is it possible to use powershell scripting to scan all console output in a powershell window, before it is outputted, and replace certain words with other words so that the altered output is displayed in the console? 是否可以使用Powershell脚本在输出之前在Powershell窗口中扫描所有控制台输出,并用其他单词替换某些单词,以便将更改后的输出显示在控制台中?

My use case is that if I replace null with an ANSI colored null, the special chars are escaped on display. 我的用例是,如果将null替换为ANSI彩色null,则特殊字符将在显示时转义。 I want to unescape them on display to show in color. 我想取消显示它们的显示颜色。

For example; 例如; \\pset null '[91m[0m' \\ pset null'[91m [0m'

displays null in the console as \\x1B[91m\\x1B[0m 在控制台中将null显示为\\ x1B [91m \\ x1B [0m

So I would wish replace all instances of this with a delicious ANSI colored null everywhere in the console window. 因此,我希望在控制台窗口中的所有位置都将其所有实例替换为可口的ANSI,颜色为null。

Thanks in advance 提前致谢

I don't know about scanning output, but you can always "-replace" anything that might generate output: 我不了解扫描输出,但是您始终可以“替换”任何可能生成输出的内容:

eg 例如

{write-host "Hey, this is stuff"} -replace "stuff","things" {write-host“嘿,这是东西”}-替换“ stuff”,“ things”

[System.Reflection.Assembly]::LoadFile("C:\\windows\\assembly\\GAC_64\\System.Data\\2.0.0.0__b77a5c561934e089\\System.Data.dll") -replace "4.0.0.0","3.1415" [System.Reflection.Assembly] :: LoadFile(“ C:\\ windows \\ assembly \\ GAC_64 \\ System.Data \\ 2.0.0.0__b77a5c561934e089 \\ System.Data.dll”)-替换“ 4.0.0.0”,“ 3.1415”

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

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