Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Trouble with Win32::GUI app spawning child processes

by reasonablekeith (Deacon)
on Apr 17, 2008 at 09:11 UTC ( #681082=perlquestion: print w/replies, xml ) Need Help??

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

Monks, I have a simple Win32::GUI app that runs in the system tray, checking on some of our servers and changing colour when things go wrong. All well and groovey. However, in addition to this, I'd like the users to be able click the system tray icon and have their browser launch directing them to our support site. I can do this as follows...
sub NI_Click { `"C:\\PATH\\IEXPLORE.EXE" http://ourserver`; # please ignore th +e hardcoded path }
This launches IE just fine, but the systray app is then blocked until they close IE, which is bad. So I tried...
sub NI_Click { my $pid = fork(); if ($pid == 0) { `"C:\\PATH\\IEXPLORE.EXE" http://ourserver`; # please ignor +e the hardcoded path exit(); } }
Which is better in that IE starts up, and the systray app is still functioning, but has the significant draw back that the systray app crashes when you close the instance of IE that was loaded (Command line interpreter error)

I've don't really do windows gui stuff, so have no idea how to persue this. Have any monks got an pointers?

Thanks in advance, Rob

---
my name's not Keith, and I'm not reasonable.

Replies are listed 'Best First'.
Re: Trouble with Win32::GUI app spawning child processes
by BrowserUk (Patriarch) on Apr 17, 2008 at 10:03 UTC

    Two ways. Change your backticks command to

    1. system q[start http://ourserver];.

      This will launch their default browser, whichever that is, and won't block.

      Or just a new tab in the existing running instance.

    2. system 1, q["C:\\PATH\\IEXPLORE.EXE"  http://ourserver];

      This won't block either, but will start a new instance of that specific browser, if it happens to be installed, regardless of what the user prefers.

    I've don't really do windows gui stuff, so have no idea how to persue this. Have any monks got an pointers?

    Tip: Don't even consider using fork on Win32 until you are aware of how it differs from the same call on *nix.


    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.
      Many Thanks BrowserUk

      I went for the second option, which opens a new instance of IE for me, rather than the first one, which took over existing IE windows that were running (I think you got your descriptions the wrong way around.)

      I still need to find out what the difference is here though. I thought system and backticks differed only capturing output. I don't really understand why these calls don't block.

      PS Sorry for the delayed reply

      ---
      my name's not Keith, and I'm not reasonable.

        Briefly

        1. system q[ start url ]; works because it uses the win32 start command.

          The nice thing abut this is that the start command will look up the current users preferred browser and start it with the url supplied. So, for you it may start IE, but the same command for me it would start Opera. For someone else it might start Firefox.

          For details type help start at a command window.

        2. start 1, ... works because under win32, Perl has a built-in extension that does an asynchronous spawn if the first parameter to system is the magic token '1'.

          I can't point you to the documentation because I found out about it right here at PM. Probably from tye.

          Possibly here, or here or here ...


        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.
Re: Trouble with Win32::GUI app spawning child processes
by Anonymous Monk on Apr 17, 2008 at 10:16 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (5)
As of 2022-08-17 19:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?