Changeset 35415


Ignore:
Timestamp:
2021-09-17T16:41:40+12:00 (3 years ago)
Author:
kjdon
Message:

OpenOfficeConverter.pm's BEGIN block running soffice in the background on windows using start, ended up causing GLI to hang (cmdline building didn't hang). It was because of the join() calls on the perl process' stdout/stderr in Safeprocess.InputStreamGobblers() hanging because no eof/eos was received. soffice or other silent external programs launched through perl using system() kept stderr/stdout open even though the external program was supposedly launched in the background. After lots of investigation, Dr Bainbridge found that unlike the system() command in perl/C/C++, Java programs using Runtime.exec() and WScriptHost/CScriptHost script files (like VBScript) can launch external programs fully in the background so that this hanging in GLI doesn't occur. Dr Bainbridge decided we should go with a custom VBScript, created in background-launcher.vbs (committed previously, revision 35414) instead of a Java Program as compiling and setting JAVA_HOME or updating PATH not necessary.

Location:
gs2-extensions/open-office/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • gs2-extensions/open-office/trunk/src/perllib/plugins/OpenOfficeConverter.pm

    r32323 r35415  
    100100        $status = system("which soffice >nul 2>&1"); # which.exe should be in bin/windows
    101101        if ($status == 0) {
    102             $cmd = "start \"soffice process\" $cmd >nul 2>&1"; # order of >nul and 2>&1 matters, see below
     102            #$cmd = "start \"soffice process\" $cmd >nul 2>&1"; # order of >nul and 2>&1 matters, see below
     103           
     104            # On Windows, when perl/C/C++ uses system() to launch any standalone process in the background
     105            # with "start \"window title\" cmd", perl's child process (despite being mostly independent/detached
     106            # from perl) *appears* to share stdout/stderr (stdin) streams with the parent perl process. This is
     107            # noticeable with perl launching soffice or any program that neither writes to stderr/out nor sends
     108            # eof/eos to indicate parent perl's streams are closed (e.g. Notepad).
     109            # This is *not* a problem when perl scripts are run from command line. Command line programs run fine.
     110            # But when combined with SafeProcess used by GLI, such silent standalone programs like soffice
     111            # cause GLI to hang every time right until the silent program's terminated, because SafeProcess' join()
     112            # calls on the perl child process' stderr and stdout block at SafeProcess.InputStreamGobbler.readLine(),
     113            # because these stderr/out streams didn't receive eof/eos, implying the silent grandchild process
     114            # somehow kept them open.
     115            # This is true at Windows/C's system() command level: InputStreamGobblers using join() calls (as SafeProcess
     116            # does), combined with a c++ program that uses system() that launches something like Notepad, just all block
     117            # until Notepad is closed.
     118            # When perl calls a custom java BackgroundLauncher.java program to launch an external program with Runtime.exec(),
     119            # this hanging problem doesn't happen as java's exec() is not implemented with Windows C's system().
     120            # Similarly, a WScript file (vbs or js script) that uses WinScriptHost.Run method to run an external program
     121            # also doesn't exhibit this problem. So we use a custom vbs script to launch external programs like soffice in
     122            # the background from perl (to avoid having to set up Java or have the java program compiled up by the release-kits,
     123            # since perl building scripts are not just run from GLI but are also run directly from the cmd line).
     124           
     125            $cmd = "CScript //Nologo $ENV{'GSDLHOME'}\\bin\\windows\\background-launcher.vbs $cmd";
     126           
    103127            #print STDERR "***** Tried to start-up OpenOffice with:\n$cmd\n";           
    104128        }
Note: See TracChangeset for help on using the changeset viewer.