抱歉,这是一个新手问题。但是我一直在尝试使用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/