Monday, May 4, 2009

Windows Background Process | Trick & tips

after alot of try n error... finally i can send command from browser to trigger background process and get status of the running process. 
tips&tricks:
  1. make sure u send command from browser and get status process also from browser.. 
  2. inlcude perl exe at cmd path event we alredy include it at exepath.
  3. try ur script at command line first before test it at browser.
sending command from browser:
my $exepath  = "C:/Programs/Perl/bin/perl.exe";
my $cmd  = "perl D:/site/sub_trial.pl";
require Win32::Process;
Win32::Process::Create($child_proc, $exepath, $cmd, 0, NORMAL_PRIORITY_CLASS, ".") || confess "Could not spawn child: $!";
$child_pid = $child_proc->GetProcessID();
get process status from browser:
if (kill(0,$child_pid))
{
print "Started child process id $child_pid\n";
}
else
{
print "Child process exited quickly: $cmd: process $child_pid";
}

No comments: