# Printed output from Julia script

**URL:** https://discourse.julialang.org/t/printed-output-from-julia-script/101531
**Category:** General Usage
**Tags:** io
**Created:** [July 12, 2023, 1:52pm UTC](https://discourse.julialang.org/t/printed-output-from-julia-script/101531 "2023-07-12T13:52:48Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![adam-srut](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/adam-srut/32/32514_2.png) [@adam-srut](https://discourse.julialang.org/u/adam-srut)
#### Post date: [July 12, 2023, 1:52pm UTC](https://discourse.julialang.org/t/printed-output-from-julia-script/101531/1 "2023-07-12T13:52:49Z")

</div>

Julia does not seem to be printing the output as it appears when redirected to a file.  
I have the following code in file `print_test.jl`:

```julia
for i in 1:10
     println("iteration: $i")
     sleep(1)
end

```

when I run the script like: `julia print_test.jl` the output is appearing as expected every second on the screen. But if I run the script like this: `julia print_test.jl > test.out`, the output will appear all at once only after the script is finished.  
Is there a solution so the output would be written to the file gradually?  
I am running a demanding Julia script on a cluster and I am monitoring the progress with `println()` function.

Interestingly, I observe the same issue if I submit the script to the queuing system and do not redirect to an external file:

```julia
#SBATCH --output=test.out
julia print_test.jl

```

---

<div class="post-metadata">

### Author: ![tbeason](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tbeason/32/15898_2.png) [@tbeason](https://discourse.julialang.org/u/tbeason)
#### Post date: [July 12, 2023, 1:55pm UTC](https://discourse.julialang.org/t/printed-output-from-julia-script/101531/2 "2023-07-12T13:55:10Z")

</div>

My approach on SLURM clusters is to explicitly make a separate logfile and print to it. The stdout stream is buffered and also not always directed to the slurm output file. I have been meaning to look into the various logging packages to see if they make this any easier.

---

<div class="post-metadata">

### Author: ![PeterSimon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/petersimon/32/25193_2.png) [@PeterSimon](https://discourse.julialang.org/u/PeterSimon)
#### Post date: [July 12, 2023, 3:04pm UTC](https://discourse.julialang.org/t/printed-output-from-julia-script/101531/3 "2023-07-12T15:04:28Z")

</div>

Edit: confirmed that this works, but after correcting capitalization of `stdout`:

I’m on my phone so can’t try this, but adding `flush(stdout)` after the `println` may help.

---

<div class="post-metadata">

### Author: ![piechologist](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/piechologist/32/27662_2.png) [@piechologist](https://discourse.julialang.org/u/piechologist)
#### Post date: [July 12, 2023, 3:06pm UTC](https://discourse.julialang.org/t/printed-output-from-julia-script/101531/4 "2023-07-12T15:06:26Z")

</div>

You could pipe through `cat` and the output will be unbuffered:

```shell
julia print_test.jl | cat > test.out

```

Or write to a file and simultaneously watch the output in the terminal:

```shell
julia print_test.jl | tee > test.out

```
