# Gfortran call execute\_command\_line (... , wait = .false.) still wait issue

**URL:** <https://fortran-lang.discourse.group/t/gfortran-call-execute-command-line-wait-false-still-wait-issue/2945>\
**Category:** Uncategorized\
**Created:** [March 10, 2022, 5:49pm UTC](https://fortran-lang.discourse.group/t/gfortran-call-execute-command-line-wait-false-still-wait-issue/2945 "2022-03-10T17:49:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [March 10, 2022, 5:49pm UTC](https://fortran-lang.discourse.group/t/gfortran-call-execute-command-line-wait-false-still-wait-issue/2945/1 "2022-03-10T17:49:33Z")

</div>

Dear all,

I have quick question, I try to plot while running the program. To do so I call

```auto
call execute_command_line ('wgnuplot -persist ' // 'ogpf_temp_script.gp' , wait = .false.)

```

since I specified

```auto
wait = .false.

```

therefore the code will not wait until I close the gnuplot popup window. I mean the gnuplot and the program are basically independent. It works fine with Intel Fortran, see below,

> [@How to use Fortran + gnuplot to plot in real time in just one window?](https://fortran-lang.discourse.group/t/how-to-use-fortran-gnuplot-to-plot-in-real-time-in-just-one-window/2904/11):
>
> Thank you all! @Pap @vmagnin @msz59 @KjellJorner I really appreciate you suggestions. After some checking, yes pause and reread did the trick! After installing Gnuplot (I am on windows 10 for this test), in the second line of my code as below, I added command, call execute\_command\_line ('wgnuplot -persist ' // 'ogpf\_temp\_script.gp' , wait = .false.) where ‘ogpf\_temp\_script.gp’ is my Gnuplot scipt, which I just use the one generated by ogpf library, but I added pause 1 reread a…

However, when the same code compile and run with gfortran, when the gnuplot windows popup, I have to close it, then the problem will continue to run.  
Otherwise, if I do not close the gnuplot windows as below, the program pause. Unless I close the popup window, then the code resume.

 ![image](https://global.discourse-cdn.com/free1/uploads/fortran_lang/original/2X/3/3bd8a727f10b02e120a9709ea2bb4af9ee6e6037.png)

I am a little confused. The intel fortran and gfortran behaves different.  
Does anyone know how to let gfortran really enforce

```auto

```

wait = .false.

```auto
so the gnuplot and the code can run simultaneously? 

Thank you very much in advance!
```

---

<div class="post-metadata">

**Author:** ![sblionel](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/sblionel/32/853_2.png) [@sblionel](https://fortran-lang.discourse.group/u/sblionel)\
**Post date:** [March 10, 2022, 6:47pm UTC](https://fortran-lang.discourse.group/t/gfortran-call-execute-command-line-wait-false-still-wait-issue/2945/2 "2022-03-10T18:47:09Z")

</div>

I don’t know how gfortran implements `EXECUTE_COMMAND_LINE` (I wrote the ifort implementation), but the standard says that asynchronous execution is not required to be supported:

> If the processor supports command line execution, it shall support synchronous and **may** support asynchronous execution of the command line. (16.9.73p4 - emphasis mine)

---

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [March 10, 2022, 7:09pm UTC](https://fortran-lang.discourse.group/t/gfortran-call-execute-command-line-wait-false-still-wait-issue/2945/3 "2022-03-10T19:09:25Z")

</div>

Thank you so much Dr. Fortran @sblionel !!! 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍 👍  
Yeah, the intel Fortran support asynchronous execution when `wait = .false.`

Hmmm, but like, if asynchronous execution is not supported in gfortran now, then what is the point of using `wait = .false.`? 🙂

It seems setting `wait = .false.` should mean the code after

```auto
EXECUTE_COMMAND_LINE (xxxx, wait = .false.) 

```

can just run without waiting xxxx to be finished, is it?

---

<div class="post-metadata">

**Author:** ![sblionel](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/sblionel/32/853_2.png) [@sblionel](https://fortran-lang.discourse.group/u/sblionel)\
**Post date:** [March 10, 2022, 7:43pm UTC](https://fortran-lang.discourse.group/t/gfortran-call-execute-command-line-wait-false-still-wait-issue/2945/4 "2022-03-10T19:43:29Z")

</div>

`wait=.false.` is a request. The “processor” doesn’t have to honor it. You’ll want to check with the gfortran documentation to see whether this is supposed to be supported, and if it is, file a bug report. There are some other things in the standard that are not required to be supported - Annex A in the standard lists all processor dependencies. (Curiously, though - not this one - I will look into that.)

For Intel, the Windows and Linux/Mac implementations are different. Windows uses `CreateProcess` and `WaitForSingleObject` - I no longer recall exactly what I did for Linux/Mac, but I know that asynchronous behavior was supported.

---

<div class="post-metadata">

**Author:** ![urbanjost](https://avatars.discourse-cdn.com/v4/letter/u/0ea827/32.png) [@urbanjost](https://fortran-lang.discourse.group/u/urbanjost)\
**Post date:** [March 11, 2022, 3:12am UTC](https://fortran-lang.discourse.group/t/gfortran-call-execute-command-line-wait-false-still-wait-issue/2945/5 "2022-03-11T03:12:08Z")

</div>

It has been ages since I had a problem with EXECUTE\_COMMAND\_LINE(3f). What OS and compiler version are you using? This works as expected with gfortran, ifort, and nvfortran on any Linux and Unix machine I have access to. So this program does not immediately print out the version and compiler information?

```fortran
program demo_exec
use, intrinsic :: iso_fortran_env, only : compiler_version, compiler_options
implicit none
integer :: exitstat,cmdstat
character(len=256) :: cmdmsg
   cmdmsg=''
   call execute_command_line("sleep 30", exitstat=exitstat,wait=.false.,cmdstat=cmdstat,cmdmsg=cmdmsg)
   if(cmdstat.ne.0.or.exitstat.ne.0)then
      write(*,*)cmdstat,exitstat,trim(cmdmsg)
   endif
   print '(4a)', &
      'This file was compiled by ', &
      compiler_version(), &
      ' using the options ', &
      compiler_options()
   call execute_command_line("ps", exitstat=exitstat,wait=.false.,cmdstat=cmdstat,cmdmsg=cmdmsg)
end program demo_exec

```

---

<div class="post-metadata">

**Author:** ![CRquantum](https://yyz2.discourse-cdn.com/free1/user_avatar/fortran-lang.discourse.group/crquantum/32/730_2.png) [@CRquantum](https://fortran-lang.discourse.group/u/CRquantum)\
**Post date:** [March 11, 2022, 8:38am UTC](https://fortran-lang.discourse.group/t/gfortran-call-execute-command-line-wait-false-still-wait-issue/2945/6 "2022-03-11T08:38:44Z")

</div>

Thank you @urbanjost !  
I am on Windows 10 and using Intel OneAPI 2021.4.  
The intel Fortran is doing exactly what I want, the code and the gnuplot in `call execute_command_line(gnuplot 'gnuplot persistent', xxx, wait = .false.)` they run independently. so I can get real time plot all the time. Then gnuplot can reread the file and plot like every 1 second interval.

However gfortran at on my Windows behave like I described, the `wait = .false.` have no difference from `wait = .true.`.

I also tested gnuplot on ubuntu with gfortran with `wait = .false.` . This time `wait = .false.` seems working, However the gnuplot popup window does not update automatically at every 1 second. I need to close the gnuplot popup window, then it popup gain, close, popup gain, repeat… I do see each time the content in the popup window updates, but I have to manually repeat this close-\>popup loop,

However, intel OneAPI on windows and ubuntu behave the same, I do see the gnuplot update in real time. So it seems gfortran’s `wait = .false.` is different from intel’s. I would prefer the way Intel does.

In terms of speed, on Linux, gfortran is not bad actually. Roughly the same as Intel’s, perhaps 10-20% slower but still decent. However, intel’s performace is consistent on windows and linux. While gfortran’s speed on windows (at least for my code) seems is about 2-3 slower than intel’s. My gfortran flag is

```auto
-Ofast -march=native -flto 

```
