Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

Win32::Process vs Win32::Job vs ????

by roho (Chancellor)
on Feb 27, 2011 at 04:17 UTC ( #890366=perlquestion: print w/replies, xml ) Need Help??

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

I am using Win32::Process to start a program on Windows. The module works fine, but it lacks the ability to specify window attributes (minimized,maximized, normal window). I tried Win32::Job which allows window attributes to be specified and it starts the job minimized, however it does not start the job detached as Win32::Process does, so my Perl program sits and waits for the job to terminate, which is unacceptable in this case.

Does anyone know of a module that will permit a program to be started detached (like Win32::Process does) and allow window attributes to be specified (like Win32::Job does)?

P.S. A big plus for each of these modules is that they are core modules (ActiveState Perl 5.8.9) so no module installs are required when the program is deployed, but unfortunately they each solve a different part of the puzzle.

"Its not how hard you work, its how much you get done."

Replies are listed 'Best First'.
Re: Win32::Process vs Win32::Job vs ????
by GrandFather (Sage) on Feb 27, 2011 at 05:52 UTC

    Under the hood Win32::Process calls CreateProcess in Kernel32.dll to get the job done. CreateProcess does allow initial Window state to be specified by setting various members in the STARTUPINFO structure passed to it. You can call CreateProcess using Win32::API, although there is a chunk of work involved in setting it all up.

    True laziness is hard work
      there is a chunk of work involved in setting it all up much so that, personally, I find it easier to write it in XS. It is disappointing that Win32::Process is not a complete implementation of CreateProcess.
Re: Win32::Process vs Win32::Job vs ????
by BrowserUk (Pope) on Feb 27, 2011 at 08:09 UTC

    If you're shy of using Win32::API or Inline::C to gain direct access to the native API,

    --and IMO you should be, especially if there is any likelihood of your code needing to run on a 64-bit Perl--

    then I offer you a low-tech but very effective solution:

    ## remember to double your \\s if you need to interpolate system q[cmd /c start /min c:\windows\system32\notepad.exe";

    Pretty much full access to the CreateProcess() api without the hassle, and guaranteed to continue to work regardless of 32/64-bitness or compiler data model (lp64 .v. llp64).

    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.
      Thanks for the suggestion, but I moved from running "start /min ..." in a system call to Win32::Process so I could kill the process via its process id later in the same script, and that all works fine. My current "minimize" workaround (which I don't particularly like) is to sleep x number of seconds after launching the first program via Win32::Process to give the program time to initialize and start running (takes a little while), before starting the second program. This allows the second program to be in the foreground hiding the first program, which is why I wanted to run the first program minimized. It's not a perfect solution, but it does what I need for now. I agree it's a shame Win32::Process does not accept window attributes.

      "Its not how hard you work, its how much you get done."

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://890366]
Approved by GrandFather
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (5)
As of 2020-09-27 07:21 GMT
Find Nodes?
    Voting Booth?
    If at first I donít succeed, I Ö

    Results (142 votes). Check out past polls.