How to wait for a shell command to finish?

I have made a very simple weather widget. It should work but it doesn’t. For some reason the variables Code2, Code3 etc. don’t get initialized before they are needed. The problem is timing - the commands themselves should work. So, is there ANY way to wait until a shell command has actually finished before continuing? I really need to know when the “wget” has actually gathered the needed data. Now only the 1st icon is actually displayed, the rest are not because the corresponding CodeN variables are not initialized. That is not the only problem. For some reason, if I comment out the wget line, I still get only 4 images shown correctly. The 5th image still fails because apparently the resizing can’t finish fast enough. Basically ChangeIcon 5 line is executed before the resizing is finished.

What is the proper way to do these kind of things?

        Set $Url = {"} {} {"$TempUnits"} {"}
        Do {exec wget -q -O "$WeatherFile" } $Url

        Set $Code1 = (GetOutput {Test=`cat "$WeatherFile" | grep code | tail -n 5 | head -n 1 | sed -e 's/<yweather:forecast //' -e 's/\/>//'` && eval $Test && echo $code} 1 -1)
        Do {exec $[FVWM_USERDIR]/scripts/resize/resize $[FVWM_USERDIR]/images/weather/} $Code1 {.png $[FVWM_USERDIR]/images/weather/icon1.png 50 50}

        Set $Code2 = (GetOutput {Test=`cat "$WeatherFile" | grep code | tail -n 4 | head -n 1 | sed -e 's/<yweather:forecast //' -e 's/\/>//'` && eval $Test && echo $code} 1 -1)
        Do {exec $[FVWM_USERDIR]/scripts/resize/resize $[FVWM_USERDIR]/images/weather/} $Code2 {.png $[FVWM_USERDIR]/images/weather/icon2.png 50 50}

        Set $Code3 = (GetOutput {Test=`cat "$WeatherFile" | grep code | tail -n 3 | head -n 1 | sed -e 's/<yweather:forecast //' -e 's/\/>//'` && eval $Test && echo $code} 1 -1)
        Do {exec $[FVWM_USERDIR]/scripts/resize/resize $[FVWM_USERDIR]/images/weather/} $Code3 {.png $[FVWM_USERDIR]/images/weather/icon3.png 50 50}

        Set $Code4 = (GetOutput {Test=`cat "$WeatherFile" | grep code | tail -n 2 | head -n 1 | sed -e 's/<yweather:forecast //' -e 's/\/>//'` && eval $Test && echo $code} 1 -1)
        Do {exec $[FVWM_USERDIR]/scripts/resize/resize $[FVWM_USERDIR]/images/weather/} $Code4 {.png $[FVWM_USERDIR]/images/weather/icon4.png 50 50}

        Set $Code5 = (GetOutput {Test=`cat "$WeatherFile" | grep code | tail -n 1 | sed -e 's/<yweather:forecast //' -e 's/\/>//'` && eval $Test && echo $code} 1 -1)
        Do {exec $[FVWM_USERDIR]/scripts/resize/resize $[FVWM_USERDIR]/images/weather/} $Code5 {.png $[FVWM_USERDIR]/images/weather/icon5.png 50 50}

        Set $Icon1 = {weather/icon1.png}
        Set $Icon2 = {weather/icon2.png}
        Set $Icon3 = {weather/icon3.png}
        Set $Icon4 = {weather/icon4.png}
        Set $Icon5 = {weather/icon5.png}

        ChangeIcon 1 $Icon1
        ChangeIcon 2 $Icon2
        ChangeIcon 3 $Icon3
        ChangeIcon 4 $Icon4
        ChangeIcon 5 $Icon5

PS. Long lines got wrapped…

Sorry, I didn’t see this before. The only way to get FvwmScript to wait is to use PipeRead instead of Exec. I’ve actually just modified my weather FvwmScript to take advantage of the benefits of this as well, it’s much more robust than playing the guessing game of when certain calls will finish :wink:

Thanks, but it is still not working. Here is the code (with simplified paths…) which resizes the weather icon to correct size:

If (RemainderOfDiv (GetTime) 5)==0 Then
  Do {PipeRead "resize icons/} $Code0 {.png icon0.png 100 100"}

  ChangeIcon 1 icon0.png

The above basically works but FVWM still doesn’t always wait the resizing to finish. Every now and then I see the next line in Alt-Ctrl-F1 console:

[scripts/WeatherInfo][LoadIcon]: <> Unable to load pixmap icon0.png

What on earth am I doing wrong? Is the syntax correct and are the quotes in the correct places?