Powershell脚本输出到变量-捕获Write-Host输出 [英] Powershell Script output to variable - capture Write-Host output

查看:384
本文介绍了Powershell脚本输出到变量-捕获Write-Host输出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用此脚本: https://github.com/byterogues/powershell-bittrex-api 我是从另一个脚本调用的.

Using this script: https://github.com/byterogues/powershell-bittrex-api which I call from another script.

例如

$order = .\bittrex-api.ps1 -action buylimit -market BTC-TX -quantity 1 -rate 0.00011300

bittrex-api.ps1捕获到错误并在屏幕上显示

bittrex-api.ps1 catches an error and shows this on screen

BITTREX错误:API查询返回错误. 错误消息:MIN_TRADE_REQUIREMENT_NOT_MET

BITTREX ERROR: API Query returned an error. Error Message: MIN_TRADE_REQUIREMENT_NOT_MET

如何将bittrex-api.ps1的输出捕获到变量中,以便可以在基本脚本中使用此变量?

How can I capture the output from bittrex-api.ps1 into a variable so I can use this variable in my base script?

推荐答案

您不能.该脚本使用Write-Host来输出错误. Write-Host仅将文本写入控制台,它不返回任何对象,这意味着没有要捕获的对象.

You can't. The script uses Write-Host to output the error. Write-Host only writes text to the console, it doesn't return any objects which means there's nothing to capture.

我建议修改脚本以使用其他cmdlet(如Write-ErrorWrite-Output或任何其他Write-*)输出到流(您可以将其重定向到stdout-stream并保存).

I would recommend modifying the script to use other cmdlets like Write-Error, Write-Output or any other Write-* which outputs to a stream (which you can redirect to the stdout-stream and save).

请参见 http://www.jsnover .com/blog/2013/12/07/write-host-considered-harmful/

这篇关于Powershell脚本输出到变量-捕获Write-Host输出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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