How to run a program in Atom Editor?
Asked Answered
R

9

60

I found Atom editor as good free alternative to Sublime text editor. Not able to find a straightforward way to run a program in Atom editor. In my case, I am trying to run a java program. Please let me know if it's possible? If yes, please describe the steps to follow.

Rasla answered 12/6, 2015 at 9:18 Comment(2)
Solution is discussed in this similar question. #34015402Rasla
Use Script Package and then Ctrl+Shift+B to run the code. Output will be shown at bottom of ATOM. Script package is real cool stuff for ATOM.Werth
H
47

I find the Script package useful for this. You can download it here.

Once installed you can run scripts in many languages directly from Atom using cmd-i on Mac or shift-ctrl-b on Windows or Linux.

Hunt answered 16/6, 2015 at 18:35 Comment(5)
I installed scripts package and tried to run Java program in my Windows machine. But got following error: 'javac' is not recognized as an internal or external command, operable program or batch file.Rasla
Seems like script package needs some manual modification to run in Windows machine.Rasla
Is there any way to stop the started javascript(say with a timer)? Tried menu "Packages > Script > Stop Script" but it failed to work.Mutate
Also add Portable_Github & javac locations to Windows PATHFizz
I can't install the package from the website. However I did it in atom inside. If anyone who is facing the same problem, go to "File => Settings => Install" and search for "script" and installLewanna
D
38
  1. Click on Packages --> Commmand Palette --> Select Toggle.
  2. Type Install Packages and Themes.
  3. Search for Script and then install it.
  4. Press Command + I to run the code (on Mac)
Dissident answered 1/5, 2016 at 4:6 Comment(4)
I have installed the Script, and restart Atom, it works for me.Celebrate
I think atom-runner is better because when using Script the code in current window moves a few lines horizontally. Maybe it's just a bit broken at the moment?Roane
Script works sometimes for me. I notice when I run Ruby scripts it try's to run Rails. It's wonky that way. I've noticed that shutting it down and starting Atom back up works for a while. Too bad because I was starting to like working in Atom, with VIM mode. I always go back to VIM or macvim, I hope they fix Script. Atom has some nice features that I like over ViM.Calibre
I can't speak about Java running in Atom but it works great in eclipse or better in IntelliJ IDEA (best editor for Java imho)Calibre
D
4

For C/C++ programs there's very good package gpp-compiler.

Shortcuts:

  • To compile and run: F5
  • To debug: F6
Dorso answered 10/4, 2017 at 7:37 Comment(2)
Thanks. How can we configure it to other keybinding ?Dermis
I'm not sure but it should be in the file/settings/keybindings.Occupier
O
4

You can go settings, select packages and type atom-runner there if your browser can't open this link.

To run your code do Alt+R if you're using Windows in Atom.

Occupier answered 15/2, 2020 at 10:18 Comment(0)
H
2

If you know how to launch your program from the command line then you can run it from the platformio-ide-terminal package's terminal. See platformio-ide-terminal provides an embedded terminal within the Atom text editor. So you can issue commands, including commands to run your Java program, from within it. To install this package you can use APM with the command:

$ apm install platformio-ide-terminal --no-confirm

Alternatively, you can install it from the command palette with:

  • Pressing Ctrl+Shift+P. I am assuming this is the appropriate keyboard shortcut for your platform, as you have dealt ith questions about Ubuntu in the past.
  • Type Install Packages and Themes.
  • Search for the platformio-ide-terminal.
  • Install it.
Hulky answered 7/11, 2016 at 8:58 Comment(0)
H
2

This package in Atom can run scripts.

Atom script package

press Alt+X for the running script.
For running javascript you need to install 'node js'

Also pressing ctrl+shift+i in atom gives developer option like chrome

you can test javascript code side by side in atom editor.

Hambrick answered 3/9, 2017 at 4:55 Comment(0)
V
1

In order to get this working properly on Windows, you need to manually set the path to the JDK (...\jdk1.x.x_xx\bin) in the system environment variables.

Valenta answered 6/5, 2016 at 8:33 Comment(6)
I added JDK path in environment variables. After, I get following error: javac: file not found: EnergySource.java Usage: javac <options> <source files> use -help for a list of possible optionsRasla
I spent sometime in editing CoffeScript file [grammars.coffee] of Script package.Rasla
Script for Java in Windows doesn't seem to append correct class path for the current Java file.Rasla
@Omkar I have encountered the same issue. To make it work either 1) open atom form the command line in the directory where the desired Java source file is located or 2) right-click your Java source file and then try building - now it must work. In other words the problem seems to be that the file path to a file that you try to build is not correctly set. If you look in the ~\.atom\packages\script\lib\grammars.coffee you will see that for building Java files on Windows it uses just filename without full path. I must say this is not what I expected, not convenient...Firooc
@Firooc First option worked magically. Not sure to get second method. I don't see build option on right clicking source file in editor. But for clean solution, agree that grammars.coffee should consider full path for the file.Rasla
@Omkar Actually what I meant is right-click on the Java file in the Windows Explorer and choose "Open with Atom". This way Atom gets the full path to your Java file correctly.Firooc
G
0

You can try to use the runner in atom Hit Ctrl+R (Alt+R on Win/Linux) to launch the runner for the active window. Hit Ctrl+Shift+R (Alt+Shift+R on Win/Linux) to run the currently selected text in the active window. Hit Ctrl+Shift+C to kill a currently running process. Hit Escape to close the runner window

Gentilism answered 20/10, 2016 at 11:15 Comment(0)
E
0

You can run specific lines of script by highlighting them and clicking shift + ctrl + b

You can also use command line by going to the root folder and writing: $ node nameOfFile.js

Economizer answered 3/2, 2020 at 1:19 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.