in reply to Hiding programs launched within wperl'd script

Try

$tlist = `start /b tlist`;

That said, you might consider using Win32::Process::Info to obtain the information you're after.


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco. -- Rule 1 has a caveat! -- Who broke the cabal?
"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^2: Hiding programs launched within wperl'd script
by mdog (Pilgrim) on Jan 18, 2006 at 00:28 UTC
    Hey BrowserUK --

    I tried $tlist = `start /b tlist`; on XP and it still fires off the tlist window when run from wperl.exe. Just realized, I think I'm seeing the "start" window doing it this way...same problem.

    Also, I originally was using Win32::Process::Info but the overhead to fire that up is insane compared to tlist. It seriously takes about 20 times the juice to do this.

    I'd like to know how to do this for my own edification so that in the future I can fire off other programs I might shell out to without their windows coming up; however, my goal for this project is to check every 5 seconds or so to see if a program is running.

    So if there is a low overhead way to do this, I'd love to know...I've thought I could write some daemon that keeps track of process info that I could connect to and read data from or read a text file from...but this seems like overkill for something so simple. Using Win32::Process::Info it ate 20% of my CPU...tlist took 1% sometimes.

    Many thanks for your ideas!
    Matt

      In a wperl.exe app, I run the following at startup:
      my $AllocConsole = new Win32::API('kernel32', 'AllocConsole', [] , 'N' +); my $GetConsoleWindow = new Win32::API('kernel32', 'GetConsoleWindow', +[] , 'N'); my $ShowWindow = new Win32::API('user32', 'ShowWindow', ['N','I'] , 'N +'); my $apival = $AllocConsole->Call(); if($apival) { my $console = $GetConsoleWindow->Call(); my $hidewindow = 0; my $rval = $ShowWindow->Call($console, $hidewindow); }
      So I've now got a hidden console window that any console apps I call will run in. The console may flash once on app startup, but after that you're OK.
        markwx --

        Thanks for the advice...Having a hidden console window to run your apps in? Great thinking...didn't even know it was possible. Haven't tested this out, yet (work is slamming) but this seems like a real winner!

        Thanks for the code sample!

        Matt

        PS Once I get something working, I will post it so folks can see.

        markwx --

        I'm having a hard time figuring out how you pass your command into the $console handle you have created to run your program and get a scalar back of the value of the program you just ran.

        If you wouldn't mind, could you post how you interact with the console?

        Much appreaciated!
        Matt