Invalid syntax with setx

前端 未结 3 1930
被撕碎了的回忆
被撕碎了的回忆 2020-12-30 23:52

I used the setx command to set OGRE_HOME:

setx OGRE_HOME D:\\Program Files\\OgreSDK

Now I need to change to value

相关标签:
3条回答
  • 2020-12-31 00:33

    setx and pretty much all windows command line commands are sensitive to certain special characters. Among them the space character but there's also the quote which is used to delimit an entry.

    As @ajp15243 already said, you can deal with the space by locking off the path{s) between two quotations. But what if you have paths and those path already have quotations because they carry a space? Here's an example:

    MY_PATHS="c:\Program Files\path1";"c:\Program Files(x86)\Path2"
    

    In this case, you would have to put escape characters for those inner quotation marks when you use setx or it will get confused and give the error you listed. Eg:

    setx -m MY_PATHS "\"c:\Program Files\path1\";\"c:\Program Files(x86)\Path2\""
    
    | improve this answer | |
    0 讨论(0)
  • 2020-12-31 00:34

    Command Prompt is giving you that error because you forgot the quotation marks. You should’ve typed:

    setx OGRE_HOME “D:\Program Files\OgreSDK”
    

    To see all the values you’ve already set, enter either:

    reg query "HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Environment"
    

    OR

    reg query HKEY_CURRENT_USER\Environment
    
    0 讨论(0)
  • 2020-12-31 00:35

    Your path to the Ogre SDK has a space character in it, which is interpreted as a delimiter to another argument. Surround your path with " to keep it as one single argument to setx:

    setx OGRE_HOME "D:\Program Files\OgreSDK"
    

    To see the current value of the OGRE_HOME environment variable:

    echo %OGRE_HOME%
    

    You may have to open a new command prompt shell to see the value if you set it and are then trying to immediately see it's value.

    To see all currently set environment variables, simply run:

    set
    

    To show only environment variables that have a certain prefix (so FOO would show FOOBAR and FOOBAZ), put that prefix after set:

    set PREFIX
    

    Alternatively, you can use the GUI to edit environment variables (assuming Windows 7 here).

    • Right-click Computer, choose Properties
    • Click Advanced system settings in the left pane
    • Make sure you're on the Advanced tab in the pop-up dialog
    • Click Environment Variables... at the bottom

    A dialog will pop up with your user-specific environment variables as well as your system-wide environment variables. Select a value and use the New/Edit/Delete buttons to interact with them.

    0 讨论(0)
提交回复
热议问题