Skip to content
← Back to Community
How do I run a file using .replit
Profile icon
h
has Hacker Plan
DynamicSquid

So I have a .replit file and it looks like this:

language: "cpp" run = ""

Now I also have a main.cpp file. So I was wondering, is there a way in which I can run the main.cpp file using the run thingy? For example can I do something like this:

language = "cpp" run = "main.cpp"

Or is that just not how things work...?

Answered by SPQR [earned 5 cycles]
View Answer
Voters
Profile icon
SHACHIRANI
Profile icon
ItsDipakPawar
Profile icon
disamsada
Profile icon
Egolas
Profile icon
firefish
Profile icon
Codemonkey51
Profile icon
DynamicSquid
Comments
hotnewtop
Profile icon
SPQR

the .replit file runs a bash command, like Codemonkey51 said. It's effectively a command for a Linux terminal (in this case, Ubuntu.)

If you want to run multiple commands at once, make a .bash file and set the command in the .replit file to run the file (i.e. bash main.bash)

A very basic example of what to write in the bash file could be this:

clang++ -std=c++2a *.cpp -o main chmod 744 main ./main

Line 1 compiles all the .cpp files in your base directory (if you want to include all files 1 folder deep, try replacing *.cpp with *.cpp */*.cpp, might be a better way of accomplishing this but I'm not sure) using the c++2a standard (which is the newest version of C++, you could use c++17 or c++14 etc instead)
Line 2 makes the main compiled program accessible
Line 3 executes the compiled program

I would honestly suggest excluding the .replit file altogether unless absolutely necessary until you understand bash at least a little bit. It's not super complex, though, and overall I think it's worth it to learn, especially if you plan on using replit a lot.

Profile icon
Bookie0

Here check this out idk if it’s gonna help tho but you can try...
https://repl.it/talk/ask/replit-run-file/25386

Profile icon
MilescOde

I think it's:
run = "cpp main.cpp"

Profile icon
Codemonkey51

So the .replit file run uses a bash command so use what command you would use to run it