0

I'm trying to run python scripts through the sublime build system (Sublime Text). I want built to start terminal, execute the program and wait till press any keys.

{
    "shell_cmd": "start cmd.exe @cmd /c python -u \"$file\" && echo. && pause",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.python",
    "shell": "true"
}

The above code executes but it terminates as soon as it completes even though pause is added. Using /k terminal stays on screen but then we have manually close it instead of pressing any key.

How to configure shell script so that it will run the code in terminal and end when a key is pressed.

8
  • Why are you opening a cmd instance from another cmd instance inside a cmd shell? Why not just "@start python -u \"$file\" & echo. & pause". Commented Sep 2, 2021 at 13:07
  • @Compo sublime build system doesn't allow to take input just output. Also, I don't want to use files for inputs. I want to take user input so, I'm opening cmd. shell_cmd is opening cmd just cmd instance. BTW I tried your command still pausing. Commented Sep 3, 2021 at 4:08
  • I have no idea what any of that means in relation to my comment. Your question stated that it was not pausing, despite you having used the pause command, your comment above is complaining that it is pausing. Now unless I'm incapable of understanding the basic mechanics of this task, it seems to me as if it has worked. Please try to properly explain the task you're trying to perform, what exactly is happening when you perform it, what exactly you'd like to happen instead, why you're complaining about not wanting to use a file, when you posted a command using a file, how user input is relevant Commented Sep 3, 2021 at 12:46
  • @Compo, sorry for me not being clear. Sublime Text provides build systems to allow users to run external programs. Examples of common uses for build systems include: compiling, transpiling, linting, and executing tests. Build systems are specified via JSON and saved in a file with the extension .sublime-build. The following is a basic example of a build system. This build system will execute the currently open Python file. "cmd": ["python", "$file"]. The executed output will be shown at bottom of Sublime; if there is an input in a python file, we can't take it through this build system. Commented Sep 3, 2021 at 18:23
  • If "cmd": ["python", "$file"] executes the python file in cmd, then why are you using "shell_cmd": "start cmd.exe @cmd /c python -u \"$file\"". When you use "cmd": or "shell_cmd": that opens the shell, i.e. cmd.exe. So once that is open you are using a built-in cmd.exe command, start to start a second cmd.exe session passing it the arguments @cmd /c python -u "$file". So the third cmd.exe command is invoked and is passed the following arguments, python -u "$file. Do you see what I mean now? you appear to be running three cmd.exe instances, just to run a python script! Commented Sep 3, 2021 at 18:37

2 Answers 2

1

python -i works fine.

{
    "shell_cmd": "start cmd.exe /c python -i \"$file\"",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.python",
    "shell": "true"
}
Sign up to request clarification or add additional context in comments.

Comments

0

As per your requirement, it would be:

    {
    "shell_cmd": "start cmd.exe /c \"python \"$file\" && pause\"",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.python",
    "shell": "true"
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.