繁体   English   中英

运行包含 <、' 和 " 的 Windows 10 Powershell 命令时出错

[英]Error while running a Windows 10 Powershell command that contains <, ', and "

根据这篇 Medium 帖子,我正在尝试使用 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 中运行。 有许多必要的改变

所以结果会是这样的

"[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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM