Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write output in the same place in the console

I like working in an IJulia notebook and would like to print the status of some process on the same line over and over again.

Taking the example given in the link below, we desire some output:

Downloading File FooFile.txt [47%]

and want to avoid something like this:

 Downloading File FooFile.txt [47%]
 Downloading File FooFile.txt [48%]
 Downloading File FooFile.txt [49%]

In case of Python I found an answer here.

What would be a solution?

like image 246
Willem Hekman Avatar asked Mar 15 '16 20:03

Willem Hekman


People also ask

How to write console output in Java?

Writing Console Output in Java refers to writing the output of a Java program to the console or any particular file. The methods used for streaming output are defined in the PrintStream class. The methods used for writing console output are print (), println () and write (). Methods of Writing Console Output in Java-print () and println ()

What are the methods used for writing console output?

The methods used for writing console output are print (), println () and write (). Both print () and println () methods are used to direct the output to the console.

What is the use of write-output command?

If Write-Output is the last command in the pipeline, the objects are displayed in the console. Writes the specified objects to the pipeline. If Write-Output is the last command in the pipeline, the objects are displayed in the console.

What is the default way to display write-output in PowerShell?

One of the built-in aliases for Write-Output is echo and similar to other shells that use echo, the default behavior is to display the output at the end of a pipeline. In PowerShell, it is generally not necessary to use the cmdlet in instances where the output is displayed by default.


1 Answers

The "magic" in the Python answer isn't unique to Python… it's just the \r character: it resets the cursor position to the beginning of the line (without creating a new line). Subsequent print instructions will just overwrite the previous text if your terminal supports such cursor movements.

In Julia:

print("Download progress: $(progress)%   \r")
flush(stdout)

You can also take a look at ProgressMeter.jl for fancier cursor movements and output.

like image 84
mbauman Avatar answered Oct 31 '22 01:10

mbauman