Four Js Development Tools Forum

General => Ask Reuben => Topic started by: Reuben B. on August 30, 2024, 01:19:24 am



Title: Ask Reuben 242 - RUN vs launchUrl
Post by: Reuben B. on August 30, 2024, 01:19:24 am
There are a number of techniques you can use to start a child program.  Key factors to take into your decision making include do you want the parent program to wait for the child program to finish?  what information needs to be passed from the parent program to the child ?  what environment will the child program launch in, are you in a desktop or web environment ? and are you using Genero Application Server ?

Read more at https://4js.com/ask-reuben/ig-242/
 


Title: Re: Ask Reuben 242 - RUN vs launchUrl
Post by: Roland W. on August 30, 2024, 08:32:13 am
Hello Reuben,

as an alternative to RUN I'm using the following code:

Code
  1. define l_result  integer,
  2.       l_error  boolean = false,
  3.       l_channel base.channel
  4.  
  5. if ((l_channel := base.channel.create()) is not null)
  6. then
  7. try
  8.   call l_channel.openpipe("ls; echo $?", "r")   # $? contains the return value of the previous command
  9.   if not l_channel.read([l_result])
  10.   then let l_error = true
  11.   else let l_error = (l_result <> 0)   # if return value <> 0, an error occured
  12.   end if
  13. catch
  14.   error "exception caught"
  15. end try
  16. call l_channel.close()
  17. end if

The main advantage is that I can check whether the command was executed successfully because I evaluate the return value. By using RUN this can become tricky (see https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_programs_RUN.html#c_fgl_programs_RUN__CATCH_EXECUTION_STATUS (https://4js.com/online_documentation/fjs-fgl-manual-html/#fgl-topics/c_fgl_programs_RUN.html#c_fgl_programs_RUN__CATCH_EXECUTION_STATUS)).

Kind regards
Roland