最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - ERROR: Invalid syntax. Default option is not allowed more than '2' time(s). Type "SETX ?&a

programmeradmin3浏览0评论

I am using Windows 10. In CMD, I tried to execute the following mand in my electron project:

setx GH_TOKEN "ghp_B3kYZy7OibM1Rka4Y3jLSiBUlvtSS717FhvE" npm run publish

And I got this error:

ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
Type "SETX /?" for usage.

The following code is the part of content of the Package.json file:

"scripts": {
    "publish": "electron-builder build -w -p onTagOrDraft"
  }

In the tutorial I am watching, this mand is entered in the Mac operating system as follows, where it works properly:

I am using Windows 10. In CMD, I tried to execute the following mand in my electron project:

setx GH_TOKEN "ghp_B3kYZy7OibM1Rka4Y3jLSiBUlvtSS717FhvE" npm run publish

And I got this error:

ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
Type "SETX /?" for usage.

The following code is the part of content of the Package.json file:

"scripts": {
    "publish": "electron-builder build -w -p onTagOrDraft"
  }

In the tutorial I am watching, this mand is entered in the Mac operating system as follows, where it works properly:

Share Improve this question edited Aug 17, 2021 at 8:35 eko 40.7k11 gold badges78 silver badges101 bronze badges asked Aug 17, 2021 at 8:34 Mehrshad FarzanehMehrshad Farzaneh 6948 silver badges25 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Use

setx GH_TOKEN "ghp_B3kYZy7OibM1Rka4Y3jLSiBUlvtSS717FhvE" && npm run publish

The && are necessary because there are two mands. Without the &&, the npm run publish will be passed as arguments to SETX

This error also occurs if the environment variable you're setting contains one or more spaces.

In this case, you may avoid the problem by enclosing the value in double quotes. Unlike SET, which would take the quotes to be part of the value, SETX excludes the quotes from your stored value.

The differences in space and quote handling by SET and SETX are shown in the examples below.

For SET with spaces, quotes are not needed (and if included, bee part of the value):

Set a value                              View the value                              
-----------------------------            -----------------------------
C:\TEMP>set MYVAR=some value             C:\TEMP>set MY
                                         MYVAR=some value

C:\TEMP>set MYVAR="some value"           C:\TEMP>set MY
                                         MYVAR="some value"

For SETX with spaces, quotes are needed (and do not bee part of the value):

Set a value                              View the value in a new window                      
-----------------------------            -----------------------------
C:\TEMP>SETX MYVAR some value
ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
Type "SETX /?" for usage.

C:\TEMP>SETX MYVAR "some value"          C:\TEMP>set MY
SUCCESS: Specified value was saved.      MYVAR=some value

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论