如何在PowerShell中输出的东西 [英] How to output something in PowerShell

查看:105
本文介绍了如何在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.

批处理脚本由 ScriptFTP ,一个FTP自动化程序执行。如果出现错误,我可以有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:


  • 写主机

  • 写输出

  • 写入错误

什么是用来写入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()方法和结果<输出code> 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.

其他写 - * 命令专用于文本输出到与其相关的数据流,并有自己的位置这样

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

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

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