In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Today, I will talk to you about the control method of PowerShell command output, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
The output of scripts and commands has always been cumbersome and inconsistent, even in the same tool. Users don't know much about tools like awk,sed or grep that we've been using these days, providing the data they want most around changes in output. The main purpose of a Windows PowerShell tenant is to have the type of output expected by the user while avoiding the need to parse the text. So how does PowerShell handle it? The answer is yes, as I explained in my previous article, what makes Windows PowerShell so special?
Before we understand that PowerShell provides cmdlets for writing data, it is important to understand how PowerShell handles output. Most Shell have a concept of data flow, the most common being stdout and stderr. PowerShell has a similar concept, which we call pipelines.
In PowerShell, there are three basic channels for data:
Output-this is what is commonly called a pipeline. Where data will be passed between commands.
Host-this is written directly to the console.
Error-this is written directly to the console, but is also stored in the $error variable.
PowerShell has many cmdlets for writing data, and there are two main ones:
Write-Host-this is a simple cmdlet. It writes data directly through the pipeline and transmits it to the console. It is very useful if you do not want to provide users with information about redundant channels.
Write-Output-it is used to write specified data directly to the pipeline. I say 'specify' because if you don't specify any value, the default value will be written to the pipe.
There are other ways to write cmdlets:
Write-Debug-if $DebugPreference is set to 'continue', debug statements are written to the console.
Write-Error-write the Error stream directly.
Write-EventLog-writes an event log.
Write-Progress-here you can write a progress bar for the user and output it to the screen. This is often used in long error commands to track their processing.
Write-Verbose-if $VerbosePreference is set to "continue", the host is written.
Write-Warning-use a warning label to write to the host
As you know, there are many ways to provide feedback to users. The key to success is to use your tools correctly. For example, you plan to display messages to users by using write-host instead of write-output. Why? Because you don't want to break your tagged output data before the user, it is important to follow the user's desired goals and maintain the integrity of the data. Using a pipeline with no extra information, users can access data that is consistent with the expected attributes without having to parse the data.
After reading the above, do you have any further understanding of the method of controlling the output of PowerShell commands? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.