Sublime Forum

Windows variable in Sublime Text Build

#1

Is there any way to use Windows variable in Sublime text build. I have ih s build system:

Is there any way to use Windows variable in Sublime text build. I have ih s build system:

 {
    "name": "Python 11",
    "cmd": ["C:/Users/user01/AppData/Local/Programs/Python/Python311/python.exe", "-u", "$file"],
    "file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
    "selector": "source.python",
    },

I would kike to change user01 to be %USERNAME% as Windows variable so I don’t have to change build system every time I switch computers. I have tried with %username% and %username but Sublime is not reading it’s value.

I would kike to change user01 to be %USERNAME% as Windows variable so I don’t have to change build system every time I switch computers. I have tried with %username% and %username but Sublime is not reading it’s value.

0 Likes

#2

The thing that knows to expand environment variables is the shell; when you use cmd you are telling windows to specifically find and execute the file specified in the first argument.

You could create a plugin that finds an expands environment variables in cmd before it triggers the build, but it’s easier to just use shell_cmd instead of cmd:

    "shell_cmd": "C:/Users/%USERNAME%/AppData/Local/Programs/Python/Python311/python.exe -u \"$file\"",
1 Like