Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Creating an independent process in Win32

by Hot Pastrami (Monk)
on May 08, 2001 at 01:10 UTC ( #78660=perlquestion: print w/replies, xml ) Need Help??
Hot Pastrami has asked for the wisdom of the Perl Monks concerning the following question:

Good day, everyone.

I've been away from the Monastery a long time, the bosses have me doing strictly Java programming these days. However, I've come across a problem whch can best be solved by applying a little Perl...

I've got a short script which sends an XML and an XSL file out to an XSLT parser, writes the output to a file, then opens a browser window with the HTML result in it. That much is easy, but the script will not stop executing until the browser window is closed. Does anybody know how to make a non-blocking call to another app in Win32?

Here's the calling line of code:
Win32::Process::Create($processObject, $iexplore, "iexplore $outputFil +e", 0, DETACHED_PROCESS, ".");

Thanks go out to anybody who can help me out with this.

Hot Pastrami

Replies are listed 'Best First'.
(tye)Re: Creating an independent process in Win32
by tye (Sage) on May 08, 2001 at 07:40 UTC

    I'd go with one of these much simpler methods:

    system(1,"iexplore $outputFile"); # or system("start iexplorer $outputFile");
    I suspect the first one will have the same problem but that the second one won't, but I'd be curious if I'm right. (:

            - tye (but my friends call me "Tye")
      I determined the problem yesterday. The script was being launched from an application directly, and it was that application that wouldn't let the script stop executing until the browser window had been closed. When I disable the application's "Capture Output" option, it works fine.

      The first way you poined out results in a "Bad Command or Filename" on my system, but your second suggestion works just as well as the one I'm using now, so I'll switch to it.

      Thanks, eh!

      Hot Pastrami

        The first way you poined out results in a "Bad Command or Filename" on my system

        Yeah, that is because I typoed "iexplorer", leaving off the final "r".

                - tye (but my friends call me "Tye")
      I had a similar problem launching a batch file on NT from a cgi program. This seems like something people would do somewhat often, but it was very hard to find support. Your method system("start iexplorer $outputFile"); works great where the normal system call stinks.

      Where did you learn that "start somesuchfile.exe" kicks off a windows program like that? I love this site, but there should be more easily searched support for Win32 eccentricities.

Re: Creating an independent process in Win32
by myocom (Deacon) on May 08, 2001 at 02:25 UTC

    What you're looking for is the Wait method. Here's a little example I whipped up:

    use strict; use Win32::Process; my $appname = "c:\\winnt\\notepad.exe"; my $cmdline = "notepad"; my $inherit = 0; my $flags = 'NORMAL_PRIORITY_CLASS'; my $currdir = '.'; my $timeout = 5000; # milliseconds my $ProcObj; Win32::Process::Create($ProcObj,$appname,$cmdline,$inherit,$flags,$cur +rdir) || die &ErrorReport(); $ProcObj->Wait($timeout); print "Done!\n"; sub ErrorReport { print Win32::FormatMessage( Win32::GetLastError() ); }
      Thanks for the response, but it seems to have the same behavior as what I already have. What I want it basically to launch the browser in another process entirely, and the script should cease to care what becomes of that other process, finishing it's own execution and exiting normally, whether the browser is still open or not.

      I tried it the way you specified, and I also tried it with $processObject->Wait(0); just as a test, and it did the same thing both times... the script just sits and waits until the browser is finally closed by the user.

      Any other ideas?

      Update: OK, in my attempts, I was just adapting my script to use the same flags and such as yours, and added the Wait() command, and had no success. But when I run yours exactly as you sent it (except changing the path to Notepad to be consistent with Win9x), it works OK. There must be something up someplace else in my code. Thanks for the help, I guess I gotta jusy go through the rest of my script and find the inconsistency.

      Hot Pastrami

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://78660]
Approved by root
and the fog begins to lift...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2018-06-21 06:52 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (117 votes). Check out past polls.