How to use setx command in a windows batch file

前端 未结 4 949
轻奢々
轻奢々 2021-02-09 10:05

I am trying to create a windows batch file to automatically set the environment variable to use python 2.4 or python 3.3.

Both python 2.4 and 3.3 are installed on my sys

4条回答
  •  遥遥无期
    2021-02-09 10:26

    The Windows command line error:

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

    Summary:

    You are using a setx command and assigning it multiple tokens when only one is allowed.

    How to reproduce this error on Windows:

    Open a windows cmd terminal and enter these commands. This throws the error:

    C:\Users\Charity>setx FANCYPANTS string with spaces
    
    ERROR: Invalid syntax. Default option is not allowed more than '2' time(s).
    Type "SETX /?" for usage.
    

    Do the same command, but quote your string like this:

    C:\Users\Charity>setx FANCYPANTS "string with spaces quoted"
    SUCCESS: Specified value was saved.
    C:\Users\Charity>
    

    The variable was set, restart the cmd terminal here to load changes.

    C:\Users\Charity>echo %FANCYPANTS%
    string with spaces quoted
    

    The environment variable is saved. Now delete it.

    C:\Users\Charity>setx FANCYPANTS ""
    SUCCESS: Specified value was saved.
    

    restart the cmd terminal here to load changes. Print contents again.

    C:\Users\Charity>echo %FANCYPANTS%
    %FANCYPANTS%
    

    the variable FANCYPANTS was deleted and no longer exists.

提交回复
热议问题