Search code examples
pythonwindows-7sublimetextsublimetext3build-system

How to show result of python script in a console when running from ST editor?


I'm new to Sublime Text so am unfamiliar with its internals so far. From what I could tell the problem could be something related to this.

I have a python script

var = raw_input("Enter something: ")
print "You entered ", var

which asks for input, waits for it, then prints it out in windows console prompt.

How do I make ST3 upon "building" to show the results in a console window?


Solution

  • It's really simple just issue a command to start a new cmd.exe.

    start cmd /K python main.py
    

    See here for more(ancient)

    The /k flag "pipes" the other commands to cmd.exe and runs until you exit the shell yourself, useful for when you want to see traces.

    The /C flag "pipes" the other commands to cmd.exe and runs until the python program has finished.

    So in your project-file you should have something like this:

    "build_systems": [
        {
            "name": "RunPY",
            "cmd": ["start", "cmd", "/K", "python", "main.py"],
            "shell": true,
            "working_dir": "<project_path>"
        },
    
    ]
    

    While we're on the topic of build_systems in Sublime I would like to recommend the plugin BuildSwitcher, it works okay on ST3, it just doesn't always notice when you've added a new build in your project file. This also means that you have to install the plugin manually for ST3.

    With that plugin you can easily define and run different builds with just a few key-strokes. A real timesaver.