I’m attempting to use Sublime for C development, but I am unable to get a terminal in the lower half to display any output. All it shows is the build time information (’[Finished in 150m]’). I feel like this is a simple fix but I just can’t find it.
No terminal / C program / MacOS
What does your build system look like? The one that ships with Sublime for C/C++ only compiles the program but doesn’t execute it. Picking Tools > Build With... from the menu and picking the variant with Run in the name will run it.
If you’re using a custom build system, then you would need to implement that in the build yourself (i.e. tell it not only to compile but also to run).
I created a custom build system. Here is what it looks like. When I select the run variant I still don’t get anything.
{
"shell_cmd": "clang \"$file_name\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir" : "$file_path",
"selector" : "source.c",
"variants":
[
{
"name": "Run",
"shell_cmd": "clang \"$file_name\" -Wall -o {file_path}/${file_base_name}' && {file_path}/$file_base_name'"
}
]
}
Your build has some unpaired single quotes in it which should not be there, and additionally in your Run variant the values for file_path aren’t prefixed with a $, so they’re treated as text. With those modified (changed build below) it works OK for me. Without them the build errors out with diagnostic messages related to the failed commands.
{
"shell_cmd": "clang \"$file_name\"",
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir" : "$file_path",
"selector" : "source.c",
"variants":
[
{
"name": "Run",
"shell_cmd": "clang \"$file_name\" -Wall -o ${file_path}/${file_base_name} && ${file_path}/$file_base_name"
}
]
}
Thank you for noticing (and fixing) those errors. It currently compiles fine but I still don’t get any terminal output for the Run variant. I took a screen recording of what it is doing. Thanks again for your help.
Here is the link: https://youtube.com/shorts/iXLXSVwc3QQ?feature=share
Your issue isn’t your build file, your issue is that scanf reads from stdin, and builds are output only.
To do that you need to either build and run outside of Sublime, run non-interactive programs (or augment it to read its input from elsewhere) or use Terminus to make the build interactive.
The Terminus package README includes instructions, and I also walk through it in the video below.