in reply to Re^4: Using Proc::Background and Win32
in thread Using Proc::Background and Win32

CavaPackager is a program that has a GUI you can use to 'build' perl scripts into standalone executables.
I plan on putting this program on a few different PCs around the office and don't want to have to install
Perl, as well as ALL the required Modules, espically Gtk2/Pango/Cairo/etc on each and every PC I want this on...
Which is rather time consuming.


Here is my ORIGINAL Code Snippet which executes the Background Script:
        *This is only a small snippet to get the idea...
        *FYI, the Background script opens a TCP Socket and sends some data to a server.

my $TIMEOUT = 30; my $proc; my $bg_script = "./bg_script.pl"; $proc = Proc::Background->new("perl $bg_script $ARG1 \"$ARG2\" $ARG3 $ +ARG4"); my $PID = $proc->pid; my $start_time = $proc->start_time; my $alive = $proc->alive; my $timeout_start = time; my $timeout_current; my $timeout_diff; while($alive ne 0) { $alive = $proc->alive; # This will continue the processing of Gtk Events... while (Gtk2->events_pending) { Gtk2->main_iteration; } Gtk2::Gdk->flush; $timeout_current = time; $timeout_diff = $timeout_current - $timeout_start; if ($timeout_diff >= $TIMEOUT) { last; #->Use 'last' to break out of loop if we +timed-out... } # Sleep for 1000 milliseconds usleep(1000); }

I'm not exactly sure how it works, this is my first time using the CavaPackager Program, but after it's
done it will be a ".exe" and not a ".pl" so not sure if leaving the "perl" before the script will work in
the end...


But back to the Win32::Process, does anyone think this would be better to use then using the system command
that I said I got working in my last post?

I was just kinda curious if there were any Pros and/or Cons between using that system call method I got
working, and the "Win32::Process" method (*I guess only if it differs from Proc::Background)...

But anyway, I'm heading home shortly, I think I just need to step away from this for a bit and take a breath.
My head is sort of spinning with all this stuff.


Thanks AGAIN to everyone who posted, much appreciated!!


Thanks,
Matt

Replies are listed 'Best First'.
Re^6: Using Proc::Background and Win32
by BrowserUk (Patriarch) on Oct 18, 2013 at 22:24 UTC
    But back to the Win32::Process, does anyone think this would be better to use then using the system command

    The bottom line is that all of them -- including system which ends up calling win32_spawnvp() in Win32.c -- use the OS call CreateProcess().

    What distinguishes them, is the preprocessing of the arguments and command strings, prior to calling CreateProcess(), and in that respect, system does it better than all of the others.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    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.
      Hey BrowserUK, thanks for the reply!

      Ok cool, thanks for the clarification...

      I guess I'll save myself the headache and use that system command that you posted, which you
      suggested I try.

      Which was this one here:
      Perl> $pid = system 1, 'perl', '-E"sleep 20; say q[done]"';; Perl> print kill 0, $pid while sleep 1;;


      Since the command seems to work without any problems and I can check on it's progress, then that's
      good enough for me!


      Thanks Again for the help, very much appreciated!


      Thanks,
      Matt