Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^7: exec() on Windows

by BrowserUk (Patriarch)
on May 26, 2010 at 14:38 UTC ( [id://841737]=note: print w/replies, xml ) Need Help??


in reply to Re^6: exec() on Windows
in thread exec() on Windows

Windows OS doesn't support exec in the POSIX form, just as it doesn't support fork. So these are both emulated by Perl on Windows--but not very accurately. In particular, exec will work pretty much exactly like system. Ie. It will start a new process and wait for that process to end.

If however, you use system( 1, ... ) it will start the new process asynchronously (it won't wait) and if the perl script ends, the new process will continue as if the script had never existed.

And yes. I use Windows.

Now, how about you answer the question I asked?

You've already agreed that if you replace exec with system( 1, 'yourname.html' );, and you run your script from the command line, it operates as you want it to.

But, you said "it doesn't work" if you double-click it, or a short-cut to it, and my question to you was:

WHAT ACTUALLY HAPPENS WHEN YOU DOUBLE CLICK IT, OR A SHORT CUT TO IT?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^8: exec() on Windows
by vitoco (Hermit) on May 27, 2010 at 21:48 UTC
    WHAT ACTUALLY HAPPENS WHEN YOU DOUBLE CLICK IT, OR A SHORT CUT TO IT?

    When I run my program not from a command line, IE is instructed to open the file. This is OK. What is not the expected behavior is that the script interpreter (perl.exe) WAITS for IE to close, leaving it as a console window, a button in the task bar and related things. I.e. it does not seem to be asyncroneous.

    On the other hand, I neither expected that perl.exe didn't wait when IE was already open, even if I use system() in the standard way.

    The start /B trick with system() was the best workaround in my case. Now, my script always finishes while IE (or the default browser) is loading the html report.

      Hm. Strange that, because I just tested it, (system( 1, 'the.html';) again, and it works here on my Vista machine: from the command line, double-clicking the .pl file within explorer; and double-clicking a short-cut to the .pl file. (Although I did have to modify the properties of the short cut to start it minimised to avoid the flash of the shell window.

      It also works on my old XP machine. All three ways.

      I don't use PAR:Packer, but if the only reason for using that is to conceal the perl, your AS distribution comes with utilty called pl2bat. As the name suggests, it converts the .pl file to a .bat file. So, I tried that, and that works in all three ways also.

      I've requested a friend try it on his Win2003 setup. He hasn't got back to me yet, but I'll lay odds it works there too.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        Just tested it again but with a new script:

        #!perl -w use strict; warn "(1) Starting up a browser...\n"; system(1, "son.html"); warn "(2) Browser quits...\n"; sleep 10; warn "(3) Bye, bye...\n"; exit 0;

        You were right: that form of the system() call did not wait for the browser to quit... the console showed the first two messages almost at the same time, but after 10 seconds, the third message appeared and the console did NOT close... 'til I closed the browser.

        Then, the problem is another :-(

        BTW, I do need the console to be opened, as it shows some messages about the file being generated, so it is not a flashing console.

        About pl2bat, it places your perl code inside a bat script, just to allow you to call it from a command line without having to type the .pl extension (if it is associated to perl.exe) or having to call perl.exe with your script as a parameter (if not). Anyway, you still need have perl installed in your box. pp from PAR::Packer builds an .exe file that contains the "parl" interpreter, your script and all required modules. No perl installation is needed. When run, all is extracted on the fly... of course, a 10KB script will be turned into a 4MB exe file, and there is a startup delay, but I can live with that.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://841737]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-03-19 11:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found