【问题标题】:Error while running a Windows 10 Powershell command that contains <, ', and "运行包含 <、' 和 " 的 Windows 10 Powershell 命令时出错
【发布时间】:2021-06-10 12:07:30
【问题描述】:

根据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 '&lt;' 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

我尝试了一些方法,但无法使此命令正常工作。

【问题讨论】:

标签: powershell ssl next.js escaping


【解决方案1】:

该命令用于 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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-04-22
    • 2020-01-01
    • 2017-03-29
    • 2020-02-05
    • 2012-04-28
    • 2019-07-18
    • 2021-10-08
    相关资源
    最近更新 更多