如何解决运行包含 <、' 和 " 的 Windows 10 Powershell 命令时出错
根据 this Medium post,我正在尝试使用 HTTPS 设置本地 Next.js 开发服务器。
但是当我在 Windows 10 Powershell 中运行此命令时:
openssl req -x509 -out localhost.crt -keyout localhost.key \
-newkey rsa:2048 -nodes -sha256 \
-subj '/CN=localhost' -extensions EXT -config <( \
printf "[dn]\nCN=localhost\n[req]\ndistinguished_name = dn\n[EXT]\nsubjectAltName=DNS:localhost\nkeyUsage=digitalSignature\nextendedKeyUsage=serverAuth")
我收到此错误 The '<' operator is reserved for future use.
:
At line:1 char:142
+ ... des -sha256 \ -subj '/CN=localhost' -extensions EXT -config <( \ prin ...
+ ~
The '<' operator is reserved for future use.
+ CategoryInfo : ParserError: (:) [],ParentContainsErrorRecordException
+ FullyQualifiedErrorId : RedirectionNotSupported
我尝试了一些东西,但我无法让这个命令工作。
解决方法
该命令是用于 bash 的,所以显然它不能在 PowerShell 中运行。有许多必要的改变
-
PowerShell currently doesn't support process substitution(即 that
<(command)
part)所以您必须将输出保存到文件中 - PowerShell 中的 escape character 是
`
而不是\
,因此您必须将所有这些转义字符替换为正确的字符
结果应该是这样的
"[dn]`nCN=localhost`n[req]`ndistinguished_name = dn`n[EXT]`nsubjectAltName=DNS:localhost`nkeyUsage=digitalSignature`nextendedKeyUsage=serverAuth" > tmp.conf
openssl req -x509 -out localhost.crt -keyout localhost.key `
-newkey rsa:2048 -nodes -sha256 `
-subj '/CN=localhost' -extensions EXT -config tmp.conf
Remove-Item tmp.conf
但没必要排这么长的队。多行应该更易读
@'
[dn]
CN=localhost
[req]
distinguished_name = dn
[EXT]
subjectAltName=DNS:localhost
keyUsage=digitalSignature
extendedKeyUsage=serverAuth
'@ > tmp.conf
openssl req -x509 -out localhost.crt -keyout localhost.key `
-newkey rsa:2048 -nodes -sha256 `
-subj '/CN=localhost' -extensions EXT -config tmp.conf
Remove-Item tmp.conf
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。