Reputation: 109
Objective
Set up a Sublime Text 2 Build System that allows to compile and run C programs. I have been able to painfully get to this point, but now I have some things that I cannot figure out so my two mains questions:
1) I hit ctrl+b (it compiles successfully), then ctrl+shift+b and the script runs by it doesn't take any input? Is this normal?
2) If Sublime Build Systems do not take input, there must be some workarounds. For example I press ctrl+b Sublime Text 2 compiles the file but when I press ctrl+shift+b, Sublime launches cygwin, navigates to my current directory, then does ./filename.c. Is this possible? Here it says Sublime Text 2 suppresses GUIs but it is possible to make to make Sublime open MATLAB with the build system, so maybe I can do the same thing with Cygwin?
{
"cmd" : ["gcc", "-std=c89", "-pedantic", "-Wall", "$file_name", "-o", "${file_base_name}.exe"],
// "cmd" : ["bash ${file_base_name}.exe"],
"selector" : "source.c",
"path" : "C:/cygwin64/bin/",
"shell":true,
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
//"working_dir" : "$file_path"
"variants": [
{
"cmd" : ["${file_base_name}.exe"],
"name": "Run"
}
]
}
Thanks for looking.
EDIT
I am trying to give input to my executable when it runs. For example my script prompts the user to enter in a number, letter, string, etc using scanf or getchar(), and then store the result in a variable that I will use later on. Right now when I press ctrl+shift+B in Sublime Text it runs but skips all the input stuff.
That is my current build system. If it not possible to use Sublime Text 2 to enter in input, then i want to modify it to Sublime launches cygwin, navigate to my current directory, then do ./filename.c.
Upvotes: 1
Views: 1847
Reputation: 109
Someone over at the sublimetext channel on the freenode irc helped me out and answered my questions (shoutout to them on stackoverflow @Zren). Here is the final working script:
Description
Code
{
"cmd" : ["gcc", "-std=c89", "-pedantic", "-Wall", "$file_name", "-o", "${file_base_name}.exe"],
"selector" : "source.c",
"path" : "C:/cygwin64/bin/",
"shell":true,
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"variants": [
{
"cmd": ["start", "cmd", "/k", "${file_base_name}.exe"],
"name": "Run",
"shell": true
}
]
}
In the future
Hopefully Google can lead people here since Sublime Text 2 documentation is very poor, and I don't want anybody else to struggle with this simple yet time consuming problem.
Tags: Sublime Text 2, gcc, cygwin, build, c, input, Windows
Upvotes: 1