PowerShell 中的 Echo 等效脚本测试

编程入门 行业动态 更新时间:2024-10-20 05:39:33
本文介绍了PowerShell 中的 Echo 等效脚本测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想通过设置标志和在 PowerShell 脚本中输出变量和值查看整个脚本中的数据.

I would like to output variables and values out in a PowerShell script by setting up flags and seeing the data matriculate throughout the script.

我该怎么做?

例如,与以下 PHP 代码等效的 PowerShell 是什么?

For example, what would be the PowerShell equivalent to the following PHP code?

echo "filesizecounter: " . $filesizecounter

推荐答案

有以下几种方式:

Write-Host:直接写入控制台,不包含在函数/cmdlet 输出中.允许设置前景色和背景色.

Write-Host: Write directly to the console, not included in function/cmdlet output. Allows foreground and background colour to be set.

Write-Debug:直接写入控制台,如果 $DebugPreference 设置为继续或停止.

Write-Debug: Write directly to the console, if $DebugPreference set to Continue or Stop.

Write-Verbose:直接写入控制台,如果 $VerbosePreference 设置为继续或停止.

Write-Verbose: Write directly to the console, if $VerbosePreference set to Continue or Stop.

后者用于额外的可选信息,Write-Debug 用于调试(所以似乎适合这种情况).

The latter is intended for extra optional information, Write-Debug for debugging (so would seem to fit in this case).

附加:在 PSH2(至少)脚本中使用 cmdlet 绑定会自动获取 -Verbose 和 -Debug 开关参数,本地启用Write-Verbose 和 Write-Debug(即覆盖首选项变量),就像编译的 cmdlet 和提供程序一样.

Additional: In PSH2 (at least) scripts using cmdlet binding will automatically get the -Verbose and -Debug switch parameters, locally enabling Write-Verbose and Write-Debug (i.e. overriding the preference variables) as compiled cmdlets and providers do.

更多推荐

PowerShell 中的 Echo 等效脚本测试

本文发布于:2023-11-30 04:20:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648699.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   测试   PowerShell   Echo

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!