如何在 PowerShell 中输出内容 [英] How to output something in PowerShell

查看:64
本文介绍了如何在 PowerShell 中输出内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从批处理文件中运行 PowerShell 脚本.该脚本获取一个网页并检查该网页的内容是否为字符串OK".

I am running a PowerShell script from within a batch file. The script fetches a web page and checks whether the page's content is the string "OK".

PowerShell 脚本向批处理脚本返回错误级别.

The PowerShell script returns an error level to the batch script.

批处理脚本由 FTP 自动化程序 ScriptFTP 执行.如果发生错误,我可以让 ScriptFTP 通过电子邮件将完整的控制台输出发送给管理员.

The batch script is executed by ScriptFTP, an FTP automation program. If an error occurs, I can have ScriptFTP send the full console output to the administrator via E-Mail.

在 PowerShell 脚本中,如果不是OK",我想从网站输出返回值,因此错误消息包含在控制台输出中,从而包含在状态邮件中.

In the PowerShell script, I would like to output the return value from the web site if it is not "OK", so the error message gets included in the console output, and thus in the status mail.

我是 PowerShell 的新手,不确定要使用哪个输出函数.我可以看到三个:

I am new to PowerShell and not sure which output function to use for this. I can see three:

  • 写主机
  • 写输出
  • 写入错误

使用什么来写入与 stdout 等效的 Windows 是正确的?

What would be the right thing to use to write to the Windows equivalent of stdout?

推荐答案

简单地输出一些东西是 PowerShell 的美妙之处——也是它最大的优势之一.例如,常见的 Hello, World!应用程序减少到一行:

Simply outputting something is PowerShell is a thing of beauty - and one its greatest strengths. For example, the common Hello, World! application is reduced to a single line:

"Hello, World!"

它创建一个字符串对象,分配上述值,作为命令管道上的最后一项,它调用.toString()方法并将结果输出到STDOUT(默认).美的东西.

It creates a string object, assigns the aforementioned value, and being the last item on the command pipeline it calls the .toString() method and outputs the result to STDOUT (by default). A thing of beauty.

其他 Write-* 命令专门用于将文本输出到其关联的流,并有它们的位置.

The other Write-* commands are specific to outputting the text to their associated streams, and have their place as such.

这篇关于如何在 PowerShell 中输出内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆