First of all, consider upgrading from Sublime Text 2 to Sublime Text 3. Then, assuming you have a compiler installed, you need a Build Systems, which is basically a way of specifying what commands Sublime Text should call use in a terminal to build your code. Compile and run in Mac Terminal Sublime Text files. Ask Question. Up vote 0 down vote favorite. I'm working with a Mac and I want to compile and run my C files from the Terminal using a script. I've found a solution that apparently works in Linux. Here is the article in Spanish.
![]()
Active4 years, 2 months ago
I recently switched from Notepad++ to Sublime Text 2, and it's amazing. There's one thing I'd appreciate and that's compiling my files from the same environment. Sublime text has a console and a command pallets, but none of them can execute regular windows commands.
So for example, I'd simply like to run
javac program.java and java program from a console from within Sublime Text.
Is such thing possible yet? If so, how to do it?
Jawa
3,21988 gold badges2424 silver badges3535 bronze badges
![]()
DarrenDarren
4 Answers
The 'Show Console' button shows the Python console that is embedded into Sublime Text not the usual OS terminal. If you want to open a terminal in the folder containing the edited file you can try Sublime Terminal package.
EDIT: @Darren: if so then look in the Internet on how to run terminal commands from python shell, Google has a lot of links to them.
TomcatusTomcatus
If you're mainly looking to compile and run Java programs, then a build system (see full reference here) is what you're looking for. From the
Preferences menu, select Browse Packages... and navigate to the Packages/Java folder, and open the JavaC.sublime-build file:
This assumes that
javac is in the PATH used by Sublime, you may need to edit it to fit your system's setup. You can run this build system by first saving your .java file, then selecting either Tools -> Build System -> JavaC , or Tools -> Build System -> Automatic , then hitting CtrlB (⌘B on Mac).
To run the resulting
.class file, modify JavaC.sublime-build to the following:
You can then use the CtrlShiftB (⌘ShiftB on Mac) keyboard combo to execute the
Run variant of the build system. The 'working_dir': '${project_path:${file_path}}' line executes the build from the directory containing your .sublime-project file, if you don't have one it defaults to the directory containing your .java source. 'shell': true runs the 'cmd' through the shell, whether it's cmd.exe , bash , or whatever you choose. Otherwise, it just outputs through the Sublime console. The 'env' dictionary allows you to add Key:value pairs of environment variables you might want to set just for the build session. It can be in the 'Variants' section or the main one, depending on your needs.
For lots of details, check out the two links I provided at the beginning - together they contain a ton of information and some useful examples of build systems. You can also browse through the
Packages directory's subfolders and check out any .sublime-build files you find for ideas - their names are listed under Tools -> Build System (i.e., the 'Python' build system is found in Packages/Python/Python.sublime-build ).
In response to your original question, Sublime just isn't architected to support a full-fledged terminal emulator. While you can run arbitrary commands using Python's
subprocess.Popen() , I prefer to use the fantastic SublimeREPL plugin (available through Package Control) along with IPython . There are a bunch of dependencies, but easy_install ipython[all] should take care of most of that for you, as would installing through a package manager like MacPorts , yum , apt-get , etc. For Windows, precompiled binaries are available from Christoph Gohlke's Python Extension Packages for Windows repository, which includes links to all the required and optional dependencies. Make sure you're using the python.org installation of Python, though.
Once you have Python and IPython installed on your system and in Sublime's
PATH , and SublimeREPL installed, go to Tools -> SublimeREPL -> Python -> Python - IPython and you should be up and running momentarily. To execute a shell command, simply prefix it with ! - for example:
will list the contents of the current working directory, while
will assign those names to a variable. Be aware, however, that commands like
!cd .. won't actually change the current working directory, you'll need to run:
to do that. The documentation for the
os module's Files and Directories functions is very useful here (change the 2 in the URL to a 3 if you're using Python 3) - which brings up another strong point of this system: You can have multiple versions of Python on your system, and not have to depend on the stripped-down version of 2.6 that ships with Sublime Text 2. Save the following to Packages/User/SublimeREPL/config/Python/Main.sublime-menu and customize for your tastes:
Now you can have custom menu options that will survive
SublimeREPL upgrades from Package Control, and run REPLs with different options, working directories, what have you.
Hopefully some of this is of some use to you, please let me know how it works for you.
MattDMoMattDMo
It is possible now.You can compile and run your code entirely in ST, and it's very quick/simple.There's a recent ST package called Javatar that can do this.https://javatar.readthedocs.org
Compile And Run Result With Sublime Text For Mac Download
KengKeng
Compile And Run Result With Sublime Text For Mac
Try Glue, it's a terminal inside a Sublime text tab. You can run all console commands, start program's etc from a command line, the output is shown in the window.
peterpeter
Not the answer you're looking for? Browse other questions tagged command-linejavasublime-text-2 or ask your own question.Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |