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 badges2 Answers
Reset to default 4Use
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