powershell - 我该如何纠正 “Command output already redirected”错误

标签 powershell parsing error-handling

抱歉,这是一个新手问题。但是我一直在尝试使用gcloud Text to Speech API,并尝试将输出保存为文本文件。

我通过添加|将文件result.txt输出到下面的指令的最后一行。它只能运行一次,但由于它仅返回一个错误,表明输出已被重定向。

有什么想法可以解决这个问题吗?

$cred = gcloud auth application-default print-access-token
>> $headers = @{ "Authorization" = "Bearer $cred" }
>>
>> Invoke-WebRequest `
>>   -Method POST `
>>   -Headers $headers `
>>   -ContentType: "application/json; charset=utf-8" `
>>   -InFile f:\request.json `
>>   -Uri "https://texttospeech.googleapis.com/v1/text:synthesize" | Select-Object -Expand Content

//**Errors:**
At line:6 char:1
+ >>   -Headers $headers `
+ ~~~~~~~~~~~~~
The output stream for this command is already redirected.
At line:7 char:1
+ >>   -ContentType: "application/json; charset=utf-8" `
+ ~~~~~~~~~~~~~~~~~~
The output stream for this command is already redirected.
At line:8 char:1
+ >>   -InFile f:\request.json `
+ ~~~~~~~~~~~~
The output stream for this command is already redirected.
At line:9 char:1
+ >>   -Uri "https://texttospeech.googleapis.com/v1/text:synthesize" |  ...
+ ~~~~~~~~~
The output stream for this command is already redirected.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : StreamAlreadyRedirected

最佳答案

谢谢7cc-这是答案:
在每行的开头删除>>。看来您已从控制台窗口(包括“继续提示”)复制了该命令。并且它们被解释为重定向命令。

关于powershell - 我该如何纠正 “Command output already redirected”错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62089681/

相关文章:

java - 从 Klout API 将 JSON 解析为 Java

powershell - 如何在 Windows PowerShell 中进行屏幕捕获?

powershell - 将 PowerShell 变量作为 cmdlet 参数传递

ios - 将嵌套的 JSON 解析为 NSDictionary

c++ - 如何使用 boost::spirit 验证代数语句?

java - SolrJ添加数据时出错

ruby-on-rails - 更优雅地处理项目中的 Redis 需求?

c - C 库应如何提醒用户错误的输入以及其他介绍库问题

powershell - 如何将 PowerShell 脚本(而非函数)中的 set-strictMode -version 2 与 param 语句结合起来?

powershell - 基于 PowerShell 中另一个参数的值生成动态验证集