Skip to content
Sign upLog in
← Back to Community

Configuring the RUN button (Java and Python Examples)

Profile icon
MrMazzone

This tutorial will help you configure the RUN button in your repl.it project. Specifically, this example shows Python and Java files, but the information can be used to configure the RUN button for other projects.

The .replit file

To configure what the RUN button does in your project, you need to add a .replit file to your project.

Read more about the .replit file here: https://docs.repl.it/repls/dot-replit

In the .replit file you can define run as a string holding a shell command. Whatever shell command run is set to will execute when the RUN button is clicked for the project.

The easiest way to manage complex/multistep commands when the RUN button is clicked is to create a shell script (.sh). The .replit file's run can be set to execute the script by setting it to "bash filename.sh"

Example .replit file

run = "bash run_button.sh"

Java Code

For a Java project you need to compile the project using the javac command. You can either identify a .java file to compile or use *.java to compile all Java files in the folder. Then you can execute the Java class you want by using the java command followed by the class name.

javac *.java java HelloWorld

More info here if you want to learn the basics of javac: https://www.dummies.com/programming/java/how-to-use-the-javac-command/

Python Code

For a Python project, you need to use the python or python3 command to execute a python file. Simple type the file name after the python command.

python example.py

More info here if you want to learn the basics of python command line: https://docs.python.org/3/using/cmdline.html


See example repl.it project below which runs a Java and Python run when the RUN button is clicked.

Notice how my example project is actually a Lua project and we are running Python and Java code. For the most part, when you configure the RUN button this way, the project type doesn't matter.

However, if you are creating a graphics or web project, they MUST be set to a graphics project (Python Tkinter, Java Swing, Python Turtle, etc.) or web project (HTML, CSS, JS).

Let me know if you have any questions! I will try to help!


Teachers: When using GitHub classroom, include the .replit file and the shell script in your repo. Teach students how to edit the files if they need to reconfigure the RUN button. Most situations they will not need to change it.

Voters
Profile icon
sidahmedfaisal
Profile icon
MikeMcGuire1
Profile icon
BethStoudt
Profile icon
deadchoco328
Profile icon
Xag803
Profile icon
jizhihaoSAMA
Profile icon
JRandyMacdonald
Profile icon
AhmadHashmi
Profile icon
andreiCobilas
Profile icon
ErikaLira
Comments
hotnewtop
Profile icon
Highwayman

An extremely important tutorial.

Profile icon
ThusEndingTheStory

start.sh: line 5: python3: command not found exit status 127

Profile icon
MrRed307

I'm having trouble getting bash to be able to run my imported programs from GitHub, I do not know how to tell it what file to run and how. Please Help
Screenshot 2022-03-07 6.56.58 PM

image

Profile icon
idksolol

Is thare an way of running an HTML, CSS and JS file in an python repl?

Profile icon
MrMazzone

@idksolol
I don't know a way. However, doesn't mean it is not possible! If you know how to use the shell to setup the HTML file as localhost, there is a possibility the page may render... Try it with a Python Tkinter repl so you have the GUI window.

Profile icon
idksolol

@MrMazzone
thx man ;)

Profile icon
Gorgxnzola

@idksolol
works with flask

Profile icon
goalkenhighligh

Your share is the great knowledge I have gathered, you are an important person I admire, thank you https://happywheels8.com

Profile icon
MrMazzone

@goalkenhighligh
thank you!

Profile icon
zplusfour

woah!