alexanderp98 has asked for the wisdom of the Perl Monks concerning the following question:

I have the following command returning from excel before I have finished out of Excel. The perl code I'm using looks like this:

system("summarylog.xlsx"); ... ... ... ... MessageBox("Some message");

I'm seeing the message box appear while I'm still in excel. Am I executing system wrong? I'm using ActivePerl 5.14, but 5.12 has also shown this peculiarity. Thanks for your help.

Replies are listed 'Best First'.
Re: system command returns immediately before excel is exited
by ikegami (Patriarch) on Aug 15, 2011 at 20:24 UTC

    If the association instructs Windows to use DDE to open the document, no application is run by the association, so there is no application to wait for. If this is the issue, you might have better luck if you give the run the executable directly instead of just specifying the path to the document.

    Even then, it might never work as you wish when Excel is already running. Some applications check if there's another process running the same program, instruct that process to open the document, then exit. It seems likely to me that Excel is such an application.

Re: system command returns immediately before excel is exited
by ww (Archbishop) on Aug 15, 2011 at 20:25 UTC
    perldoc -f MessageBox(); No documentation for perl function `MessageBox();' found

    You'll need to give us a little more code, since "MessageBox" is NOT a Perl function.

    Is it a sub? JavaScript? a shot-in-the-dark to see just how well Perl DWIMs?

    Update: ikegami's note is probably right on target: IMPE (painful experience!), Excel versions prior to 2010 behave exactly as he surmises... and I'd be surprised if M$ has changed that in more recent versions. So, definitely, "run the executable directly"!

Re: system command returns immediately before excel is exited
by locked_user sundialsvc4 (Abbot) on Aug 16, 2011 at 00:49 UTC

    In any Windows programming situation, you want to use OLE (ActiveX) to open the document (and/or the application) “as an object.”   Perl is, of course, more than up to the task.

    If you “open a document,” Windows (of course...) launches a separate process and does not wait for it.