RE: Win32::Process Help Needed - Main Process Exits While Children Run

2009-03-11 Thread Jan Dubois
Hi Michael,

 

You may want to look at the Win32::Job module.  As long as your vendor programs 
don't get started with the "break away from job"
attribute you should be able to check the status of all processes started 
inside the job object.  Maybe some combination of the
watch() and status() methods of the watch object will do what you want.

 

Cheers,

-Jan

 

From: perl-win32-users-boun...@listserv.activestate.com 
[mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of
Michael Cohen
Sent: Wednesday, March 11, 2009 4:26 PM
To: perl-win32-users@listserv.ActiveState.com
Subject: Win32::Process Help Needed - Main Process Exits While Children Run

 


I have a piece of code that has been running for a number of years, until now.  
My vendor changed the way they created a program,
and that new program exits before its children's processes are finished.  In 
the past, the following "snippette" has worked fine for
me: 

my $progFullPath = "c:\\temp\\foobar.exe";# Not the real program 
my $commandLine = "foobar opt1 opt2"; # Again, just an example 
my $ProcessObj; 
Win32::Process::Create($ProcessObj, 
$progFullPath, 
$commandLine, 
0, 
NORMAL_PRIORITY_CLASS, 
".")|| die print Win32::FormatMessage( Win32::GetLastError() ); 
while (!($done)) { 
  $done = 1 if ($ProcessObj->Wait(100)); 
  $main->update;  # TK update 
} 


As noted above, the "Wait(100)" would work fine if the parent program does not 
exit prematurely.  However, now that that is no
longer true: 
a)  How do I determine all of the children processes on Windows (specifically 
XP at this point)? 
b)  How do I wait until all children processes are finished? 

I have been searching the web for various options for several hours, and just 
cannot come up with one at this point.  If anyone has
any suggestions, pointers, solutions, etc., I would be most appreciative of 
your help. 

Regards,
Michael Cohen

___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Win32::Process Help Needed - Main Process Exits While Children Run

2009-03-11 Thread Michael Cohen
I have a piece of code that has been running for a number of years, until 
now.  My vendor changed the way they created a program, and that new 
program exits before its children's processes are finished.  In the past, 
the following "snippette" has worked fine for me:

my $progFullPath = "c:\\temp\\foobar.exe";# Not the real program
my $commandLine = "foobar opt1 opt2"; # Again, just an example
my $ProcessObj; 
Win32::Process::Create($ProcessObj,
$progFullPath,
$commandLine,
0,
NORMAL_PRIORITY_CLASS,
".")|| die print Win32::FormatMessage( Win32::GetLastError() );
while (!($done)) {
  $done = 1 if ($ProcessObj->Wait(100)); 
  $main->update;  # TK update 
}


As noted above, the "Wait(100)" would work fine if the parent program does 
not exit prematurely.  However, now that that is no longer true:
a)  How do I determine all of the children processes on Windows 
(specifically XP at this point)?
b)  How do I wait until all children processes are finished?

I have been searching the web for various options for several hours, and 
just cannot come up with one at this point.  If anyone has any 
suggestions, pointers, solutions, etc., I would be most appreciative of 
your help.

Regards,
Michael Cohen___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Calling subroutine from different file

2009-03-11 Thread Brian Raven
From: perl-win32-users-boun...@listserv.activestate.com
[mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of
Perl Perl
Sent: 11 March 2009 16:50
To: perl-win32-users@listserv.activestate.com
Subject: Calling subroutine from different file

> Dear All,
>  
> I have coded few scripts as mentioned below. My aim is to call the
files and function without using a extra 
> file ( call.pl as mentioned below) and with the single click. 
>  
> I have two files,  
> file1.pl & file2.pl 
> In above files, I will call the common subroutine ( say code_send() )
which is  located in fun.pl .

Put common functions in a module, for example, If the file
CommonFunctions.pm contained the following:

-
use strict;
use warnings;

package CommonFunctions;

use base qw{Exporter};

our @EXPORT_OK = qw{code_send};

sub code_send {
print "This is code_send\n";
}

1;
-

Any scripts that want to use that function will include:

-
use CommonFunctions qw{code_send};
...
code_send();
-

See 'perldoc perlmod' for documentation on Perl modules, and 'perldoc
Exporter' on exporting symbols from modules.


>  
> Now my task is to execute the above scripts in one click.
> So I thougt  to create a file by name 
> call.pl
> here in this file I will add two system calls as below.
> system("perl file1.pl");
> system("perl file2.pl");
>  
> I hope there is a better way to do this. If it is then please help me.

I'm not sure that I understand what you are asking. Unless it is
feasible to put the code from file1.pl and file2.pl into a single file,
the executing them in sequence seems a reasonable thing to do.

HTH

-- 
Brian Raven 

---
This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy. Any unauthorised copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.


___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Re: Calling subroutine from different file

2009-03-11 Thread Perl Perl
Thanks David for your prompt reply.
I have done that, but I want to avoid using call.pl here, or atleaset would
like to avoid number of files.
It is for sure that, I should use file1.pl and file2.pl, because these two
files are working on different kind of data.

Hope I am clear here.


On 3/11/09, David M. Funk  wrote:
>
>  Mujju,
>
>
>
> Try using the require statement in call.pl
>
>
>
> Example call.pl
>
>
>
> C:\perl\bin\perl.exe
>
> #some script
>
> my $cnt=0;
>
>
>
> sub do_something {
>
> .
>
> .
>
> .
>
> }
>
>
>
> ### Main 
>
> require c:\perl\script\file1.pl;
>
> require c:\perl\script\file2.pl;
>
> do something else;
>
> &do_something;
>
> print “something\n”;
>
> exit 0;
>
>
>
>
>
> now file1.pl
>
> ---
>
> sub file1 {
>
>
>
>   do stuff here;
>
>   .
>
>   .
>
>
>
> }
>
>
>
> 1;
>
> *From:* perl-win32-users-boun...@listserv.activestate.com [mailto:
> perl-win32-users-boun...@listserv.activestate.com] *On Behalf Of *Perl
> Perl
> *Sent:* Wednesday, March 11, 2009 12:50 PM
> *To:* perl-win32-users@listserv.activestate.com
> *Subject:* Calling subroutine from different file
>
>
>
> Dear All,
>
>
>
> I have coded few scripts as mentioned below. My aim is to call the files
> and function without using a extra file ( call.pl as mentioned below) and
> with the single click.
>
>
>
> I have two files,
>
> file1.pl & file2.pl
>
> In above files, I will call the common subroutine ( say code_send() ) which
> is  located in fun.pl .
>
>
>
> Now my task is to execute the above scripts in one click.
>
> So I thougt  to create a file by name
>
> *call.pl*
>
> here in this file I will add two system calls as below.
>
> system("perl file1.pl");
>
> system("perl file2.pl");
>
>
> I hope there is a better way to do this. If it is then please help me.
>
>
>
> Regards,
>
> Mujju
>
>
>


-- 
--
Regards,
Mujju
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: Calling subroutine from different file

2009-03-11 Thread David M. Funk
Mujju,

 

Try using the require statement in call.pl

 

Example call.pl

 

C:\perl\bin\perl.exe

#some script

my $cnt=0;

 

sub do_something {

.

.

.

}

 

### Main 

require c:\perl\script\file1.pl;

require c:\perl\script\file2.pl;

do something else;

&do_something;

print "something\n";

exit 0;

 

 

now file1.pl

---

sub file1 {

 

  do stuff here;

  .

  .

 

}

 

1;

From: perl-win32-users-boun...@listserv.activestate.com
[mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of Perl
Perl
Sent: Wednesday, March 11, 2009 12:50 PM
To: perl-win32-users@listserv.activestate.com
Subject: Calling subroutine from different file

 

Dear All,

 

I have coded few scripts as mentioned below. My aim is to call the files and
function without using a extra file ( call.pl as mentioned below) and with
the single click. 

 

I have two files,  

file1.pl & file2.pl 

In above files, I will call the common subroutine ( say code_send() ) which
is  located in fun.pl .

 

Now my task is to execute the above scripts in one click.

So I thougt  to create a file by name 

call.pl

here in this file I will add two system calls as below.

system("perl file1.pl");

system("perl file2.pl");
 

I hope there is a better way to do this. If it is then please help me.

 

Regards,

Mujju




___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


Calling subroutine from different file

2009-03-11 Thread Perl Perl
 Dear All,

I have coded few scripts as mentioned below. My aim is to call the files and
function without using a extra file ( call.pl as mentioned below) and with
the single click.

I have two files,
file1.pl & file2.pl
In above files, I will call the common subroutine ( say code_send() ) which
is  located in fun.pl .

Now my task is to execute the above scripts in one click.
So I thougt  to create a file by name
*call.pl*
here in this file I will add two system calls as below.
system("perl file1.pl");
system("perl file2.pl");

I hope there is a better way to do this. If it is then please help me.

Regards,
Mujju
___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs


RE: implied variables (what are they actually?)

2009-03-11 Thread Brian Raven

From: perl-win32-users-boun...@listserv.activestate.com
[mailto:perl-win32-users-boun...@listserv.activestate.com] On Behalf Of
Greg Aiken
Sent: 10 March 2009 21:20
To: perl-win32-users@listserv.activestate.com
Subject: implied variables (what are they actually?)

> while (<>) {#line1
> print; #line2
> }
>  
> I read one may create a 'filter' by running the above as;
> prog.pl < file_contents_to_send_to_prog_pl.txt

Actually you don't need a script to do that, 'perl -p' does the same
thing. (See 'perldoc perlrun' for details).

>  
> I know this is using a couple of 'implied' variables, as clearly no
direct variable names are being used here.

The two special variables in use are $_ and the null file handle. Many
functions and operators use $_ by default, see 'perldoc pperlop' and
'perldoc perlfun', and 'perldoc perlvar' for a description of $_. You
can replace the use of $_ in your script by changing '<>' to 'my $var =
<>', and 'print' to 'print $var'.

You cannot simply replace the null filehandle with a specific one, as
this use of the null filehandle has additional 'magic'. See the
description of I/O operators in 'perldoc perlop'.

>  
> But so that I could add some better control of this program, can
anyone please tell me what the ACTUAL VARIABLE > name is that is being
internally used in '<>' (line 1)?
>  
> And what ACTUAL VARIABLE name is being internally used in 'print;'
(line 2).
>  
> I would like to modify the above program so that it will run with
variable names that can be seen, as a 
> learning exercise...

The learning exercise will be more effective if you read the
documentation for the syntax, operators and functions that want to you
use. If you still have questions after a combination of reading the
documentation, and trial and error, please ask in fora like this.

HTH

-- 
Brian Raven 

---
This e-mail may contain confidential and/or privileged information. If you are 
not the intended recipient or have received this e-mail in error, please advise 
the sender immediately by reply e-mail and delete this message and any 
attachments without retaining a copy. Any unauthorised copying, disclosure or 
distribution of the material in this e-mail is strictly forbidden.


___
Perl-Win32-Users mailing list
Perl-Win32-Users@listserv.ActiveState.com
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs