Reputation: 3314
So I want to make the 'Run' variant build and run the target file, not just build it. In Linux I could just do && ./$file
or w/e but how can I do this in Windows?
{
"cmd": ["gcc", "-o", "$file_base_name", "$file"],
"variants": [
{
"cmd": ["start", "cmd", "/k", "$file_base_name"],
"shell": true,
"name": "Run"
}
]
}
Upvotes: 0
Views: 170
Reputation: 102852
Have you tried just doing the following?
{
"cmd": ["gcc", "-o", "$file_base_name", "$file"],
"variants": [
{
"cmd": ["gcc", "-o", "$file_base_name", "$file", "&&", "start", "cmd", "/k", "$file_base_name"],
"shell": true,
"name": "Run"
}
]
}
&&
works the same way on the Windows cmd
command line as it does in Unix/Linux shells. Unfortunately, if you're just reading out the results of your build command in the bottom pane of Sublime, &&
doesn't seem to work, at least on the latest build of ST3 on Win8. So, you can just fall back to a good old batch file:
@echo off
gcc -o %1 %2
%1
Save this someplace in your PATH
as buildandrun.bat
. Next, create a new build system:
{
"cmd": ["buildandrun.bat", "$file_base_name", "$file"],
"selector": "source.c"
}
and save it as %APPDATA%\Sublime Text 3\Packages\User\buildandrun.sublime-build
. Select your source file in Sublime, go to Tools -> Build System
and select buildandrun
down at the bottom, then hit CtrlB to build.
Upvotes: 1