Page 1 of 1

RunProgram with #PB_Program_Wait does not wait

Posted: Mon May 11, 2020 2:39 pm
by Jörg Burdorf
Hi Folks!

In my program I want to start the editor of the OS where it is running to edit a SQL Statement.

In Windows and Linux it runs fine. The editor was started and my program waits until the editor is closed.
On MacOS the Editor is also started, but the program does not wait until the editor is closed.

Her the Coding:

Code: Select all

CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_MacOS
      RunProgram("open","spoc"+Str(ProgramID)+".txt" ,"",#PB_Program_Wait)      
    CompilerCase #PB_OS_Linux
      RunProgram("gedit","spoc"+Str(ProgramID)+".txt","",#PB_Program_Wait)      
    CompilerCase #PB_OS_Windows
      RunProgram("spoc"+Str(ProgramID)+".txt","","",#PB_Program_Wait)
  CompilerEndSelect
  
Any Ideas ?
regards
Jörg

Re: RunProgram with #PB_Program_Wait does not wait

Posted: Tue May 12, 2020 10:37 am
by NicTheQuick
The problem is that the "open" command looks up which other program it should run for the given file type, then runs that program and exits.

You should get the same issue on Linux if an other 'gedit' instance is already running because it will just put that instance to the foreground, opens the file in it, and exits as well.

Re: RunProgram with #PB_Program_Wait does not wait

Posted: Tue May 12, 2020 4:02 pm
by Jörg Burdorf
Thanks for your hint!

I try another RunProgram call and it works so that my program is waiting:

Code: Select all

  CompilerSelect #PB_Compiler_OS
    CompilerCase #PB_OS_MacOS
      RunProgram("/Applications/TextEdit.app/Contents/MacOS/TextEdit",GetCurrentDirectory() + "/spoc"+Str(ProgramID)+".txt" ,"",#PB_Program_Wait)      
    CompilerCase #PB_OS_Linux
      RunProgram("gedit","spoc"+Str(ProgramID)+".txt","",#PB_Program_Wait)      
    CompilerCase #PB_OS_Windows
      RunProgram("spoc"+Str(ProgramID)+".txt","","",#PB_Program_Wait)
  CompilerEndSelect
Now it works!

Re: RunProgram with #PB_Program_Wait does not wait

Posted: Tue May 19, 2020 2:42 pm
by Jörg Burdorf
Hi folks!

I tried an other way to solve the problem:

The open command has a lot of parameters. 2 of them are my coice: -e means that the given file will be opened by the TextEdit App. The -W parameter means that the open command waits of the return of the command. So that is what I need.

Sample:

Code: Select all

      RunProgram("open","-W -e spoc"+pgmid$+".txt" ,"",#PB_Program_Wait)      
regards
Jörg