不带 CR-LF 的 Powershell 管柱 [英] Powershell pipe string without the the CR-LF
本文介绍了不带 CR-LF 的 Powershell 管柱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是 PowerShell 的菜鸟,我想将包含空字符的字符串传递给命令(当前工作目录中的 openssl):
I'm a total noob in PowerShell and I wanted to pass a string containing a null character to a command (openssl here in the current working directory):
powershell -command "& { \"`0myemail@gmail.com`0mypassword\" | %cd%\openssl enc -base64 }"
问题是我对我的字符串进行了编码,就好像它是通过一个回车符和一个新行字符在它的末尾传递的一样.
The thing is I'm getting my string encoded with as if it was passed with a carriage return and a new line characters at the end of it.
我错过了什么?
推荐答案
那是 openssl
的输出(坦率地说,许多/大多数 Base64 编码器在末尾放了一个换行符).
That's the output of openssl
(and frankly, many/most Base64 encoders put a newline at the end).
如果您只想直接在 powershell 中对其进行 Base64 编码:
If you want to just Base64 encode it directly in powershell:
[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes("`0hey`0"))
这篇关于不带 CR-LF 的 Powershell 管柱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文