Skip to content
← Back to Community
How to save console output/view previous runs.
Profile icon
betwixtbetween

Hi all,

I'm new to Repl and to coding. I just created a MadLib program which I've had several friends run on my computer. Usually I clear the console before every run, but I just noticed upon sitting down again that the console contained the last four stories that had been created. Does that imply that it's already saved somewhere? Or how can I save it now and in the future so I can review and share the stories created?

Thanks for considering,
Arbor

Answered by Roar123 [earned 5 cycles]
View Answer
Voters
Profile icon
betwixtbetween
Comments
hotnewtop
Profile icon
Roar123

I think if you don't clear explicitly, the repl console doesn't clear the results of the last program, but simply moves the cursor down. If you want to save your own stories, write them to a text file or possibly store the variables in a json.

Profile icon
betwixtbetween

@Roar123 Thanks for your prompt response! That makes sense--I was confused at first by the 'new file' option, but I see that I can just copy the console output to the editor side in a new file and it's saved. Cool. Is that a typical use for files in Repl, or what?

Profile icon
Roar123

@betwixtbetween Usually you would write the output of your program to a text file so you can read it later. What you're doing is also fine but text files are a way to automate something like copying.

Profile icon
betwixtbetween

@Roar123 I see. Can you give me an example of writing the output to a text file? I found a tutorial on that, but I'm interested in your take.

Profile icon
Roar123

@betwixtbetween Sure, since I don't know Ruby, I'll write an example in Python but see if you can follow the thought process.

# madlibs.txt is text file # save madlib to variable madlib = "...." # appending to text file # writing erases previous contents so append to add without erasing with open("madlibs.txt",'a') as madlibs: madlibs.write(madlib) # read text file with open("madlibs.txt",'r') as madlibs: all_madlibs = madlibs.read() print(all_madlibs)
Profile icon
betwixtbetween

@Roar123 Thank you so much for this! That's super clear, I've finally got it now.

Profile icon
Roar123

@betwixtbetween Great!

If this helped you
mark it as the answer

Profile icon
CodeLongAndPros

For me, you can scroll up, but you could put this in a file named .replit:

run='{run commmand} >> replit.log'
Profile icon
betwixtbetween

@CodeLongAndPros Thanks for your prompt response! Forgive my ignorance, but I'm confused. Do you mean each time I want to save the contents of the console so I can clear it, I should enter the code you gave into the console in a new file? Or can you be more specific?

Profile icon
CodeLongAndPros

@betwixtbetween The file .replit configures how your program runs. The snippet was incorrect it should be:

run='{run_cmd} | tee run.log'

Where run_cmd is the command used to run the program on the command line.

Profile icon
betwixtbetween

@CodeLongAndPros Great, thanks.

Profile icon
davidhcefx

It should be

run='YOUR_CMD | tee -a run.log'

instead if you like to append your result to the previous one.