[31037] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2282 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 18 21:09:50 2009

Date: Wed, 18 Mar 2009 18:09:12 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Wed, 18 Mar 2009     Volume: 11 Number: 2282

Today's topics:
        DateTime format of date <justin.0903@purestblue.com>
    Re: DateTime format of date <glennj@ncf.ca>
        How can I keep LWP::UserAgent from adding the http-equi <spasticgoblin@gmail.com>
    Re: How can I keep LWP::UserAgent from adding the http- <ben@morrow.me.uk>
    Re: How do I determine within the program what page I'm <tadmc@seesig.invalid>
        How do I determine within the program what page I'm on  <spasticgoblin@gmail.com>
    Re: How do I determine within the program what page I'm <ben@morrow.me.uk>
        Non-textual output <ryan.mccoskrie@gmail.com>
    Re: Non-textual output <1usa@llenroc.ude.invalid>
    Re: Non-textual output <rvtol+usenet@xs4all.nl>
    Re: Non-textual output sln@netherlands.com
        OT on Tomcat and Apache <cartercc@gmail.com>
    Re: OT on Tomcat and Apache <syscjm@sumire.gwu.edu>
    Re: OT on Tomcat and Apache <hjp-usenet2@hjp.at>
    Re: Perl Packager - Free to wrong pool error google@markginsburg.com
    Re: Perl Packager - Free to wrong pool error <1usa@llenroc.ude.invalid>
    Re: Perl Packager - Free to wrong pool error <ben@morrow.me.uk>
    Re: Perl Packager - Free to wrong pool error sln@netherlands.com
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 18 Mar 2009 14:21:37 -0000
From: Justin C <justin.0903@purestblue.com>
Subject: DateTime format of date
Message-Id: <64d2.49c10371.d659f@zem>

I need to output the date as six digits DDMMYY, with leading zeros where
necessary, and only the last two digits of the year. 

Looking through the documentation for DateTime I find I can only find
four digit year formats. I know there's always more than one way to do
it, but I can't see an easy way other than:

=== begin ===
#!/usr/bin/perl

use strict;
use warnings;
use POSIX;
use DateTime;

my $date = DateTime->now();

my $year = substr($date->year, 2, 2);
my $month = substr($date->dmy, 3, 2);
my $day = substr($date->dmy, 0, 2);

my $formattedDate = $day . $month . $year;
print "$formattedDate\n";
=== end ===

Is there a 'cleaner' way, just using the DateTime module?

	Justin.

-- 
Justin C, by the sea.


------------------------------

Date: 18 Mar 2009 15:03:34 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: DateTime format of date
Message-Id: <slrngs23a7.ijf.glennj@smeagol.ncf.ca>

At 2009-03-18 10:21AM, "Justin C" wrote:
>  I need to output the date as six digits DDMMYY, with leading zeros where
>  necessary, and only the last two digits of the year. 
>  
>  Looking through the documentation for DateTime I find I can only find
>  four digit year formats. I know there's always more than one way to do
>  it, but I can't see an easy way other than:
>  
> === begin ===
>  #!/usr/bin/perl
>  
>  use strict;
>  use warnings;
>  use POSIX;
>  use DateTime;
>  
>  my $date = DateTime->now();
>  
>  my $year = substr($date->year, 2, 2);
>  my $month = substr($date->dmy, 3, 2);
>  my $day = substr($date->dmy, 0, 2);
>  
>  my $formattedDate = $day . $month . $year;
>  print "$formattedDate\n";
> === end ===
>  
>  Is there a 'cleaner' way, just using the DateTime module?

Do you /need/ to use DateTime for this?  You're already using POSIX, so

    my $formattedDate = strftime "%d%m%y", localtime; 

However, you can just remove the first two digits of the year:

    my $fmtDate = $date->dmy();
    substr($fmtDate, 4, 2) = '';

or even as one line:

    substr( my $fmtDate = $date->dmy(), 4, 2) = '';
    print "$fmtDate\n";
                    

-- 
Glenn Jackman
    Write a wise saying and your name will live forever. -- Anonymous


------------------------------

Date: Wed, 18 Mar 2009 16:39:33 -0700 (PDT)
From: CronJob <spasticgoblin@gmail.com>
Subject: How can I keep LWP::UserAgent from adding the http-equiv strings from  the Head section of the page?
Message-Id: <064e4ec1-e7f7-4da8-9c1c-45021b380ffc@j39g2000yqn.googlegroups.com>

How can I keep LWP::UserAgent from adding the http-equiv strings from
the Head section of the page? When I run the following program below,
the $headers variable contains three Content-Type: listings. One from
the actual http header and one from the meta tag in the web page.

#!/usr/bin/perl -w

use LWP::UserAgent;
use HTML::Parse;
use HTML::Element;
use HTTP::Response;
use HTTP::Request;
use HTTP::Status;
use URI::URL;

my ($code, $desc, $headers, $body)=&makeRequest('GET', 'http://
www.google.com');
print "The headers:\n$headers\n";
print "The body:\n$body\n";

sub makeRequest( ) {
    ($method, $path) = @_;
    # create a user agent object
    my $ua = new LWP::UserAgent;
    $ua->agent("Mozilla/4.0");

    # request a url
    my $request = new HTTP::Request($method, $path);
    # set values in response object HTTP::Reponse
    my $response = $ua->request($request);

    # get the details if there is an error
    # otherwise parse the response object
    my $body=$response->content;
    my $code=$response->code;
    my $desc=HTTP::Status::status_message($code);
    my $headers=$response->headers_as_string;
    $body =  $response->error_as_HTML if ($response->is_error);
    return ($code, $desc, $headers, $body);
}


------------------------------

Date: Thu, 19 Mar 2009 00:17:35 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How can I keep LWP::UserAgent from adding the http-equiv strings from  the Head section of the page?
Message-Id: <vhf896-sdl2.ln1@osiris.mauzo.dyndns.org>


Quoth CronJob <spasticgoblin@gmail.com>:
> How can I keep LWP::UserAgent from adding the http-equiv strings from
> the Head section of the page? When I run the following program below,
> the $headers variable contains three Content-Type: listings. One from
> the actual http header and one from the meta tag in the web page.

See the ->parse_head method of LWP::UserAgent.

You might want to try reading the docs of the modules you are using.

Ben



------------------------------

Date: Wed, 18 Mar 2009 19:01:04 -0500
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: How do I determine within the program what page I'm on after  LWP::UserAgent follows a redirect?
Message-Id: <slrngs32q0.3gp.tadmc@tadmc30.sbcglobal.net>

CronJob <spasticgoblin@gmail.com> wrote:

> sub makeRequest( ) {
                 ^ ^
                 ^ ^

Do you know what those parenthesis mean?


>     ($method, $path) = @_;


Oh. That makes my earlier question rhetorical...

Your prototype says you take no args, but you take 2 args.

You should not use global variables like that. Use properly
scoped variables instead:

    sub makeRequest {
        my($method, $path) = @_;


>     my $ua = new LWP::UserAgent;

>     my $request = new HTTP::Request($method, $path);

>     my $response = $ua->request($request);


You use spaces around operators. That is a good style.


>     my $body=$response->content;
>     my $code=$response->code;
>     my $desc=HTTP::Status::status_message($code);
>     my $headers=$response->headers_as_string;


You do not use spaces around operators. That is an ungood style.


>     $body =  $response->error_as_HTML if ($response->is_error);


Toggle the style back to using spaces around operators.


> Thanks in advance for any insight.


Adopt a consistent programming style.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"


------------------------------

Date: Wed, 18 Mar 2009 16:26:56 -0700 (PDT)
From: CronJob <spasticgoblin@gmail.com>
Subject: How do I determine within the program what page I'm on after  LWP::UserAgent follows a redirect?
Message-Id: <4d105c85-b6ff-460a-ad3e-95404197cf5e@j8g2000yql.googlegroups.com>

How do I determine within the program what page I'm on after
LWP::UserAgent follows a redirect? Is there a way I can determine
whether redirects has occurred and if so how many redirects were
followed and what there urls were? (obviously I know what the first
one was)

Code snippet:

sub makeRequest( ) {
    ($method, $path) = @_;
    # create a user agent object
    my $ua = new LWP::UserAgent;
    $ua->agent("Mozilla/4.0");

    # request a url
    my $request = new HTTP::Request($method, $path);
    # set values in response object HTTP::Reponse
    my $response = $ua->request($request);

    # get the details if there is an error
    # otherwise parse the response object
    my $body=$response->content;
    my $code=$response->code;
    my $desc=HTTP::Status::status_message($code);
    my $headers=$response->headers_as_string;
    $body =  $response->error_as_HTML if ($response->is_error);
    return ($code, $desc, $headers, $body);
}

Thanks in advance for any insight.


------------------------------

Date: Thu, 19 Mar 2009 00:15:25 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: How do I determine within the program what page I'm on after  LWP::UserAgent follows a redirect?
Message-Id: <tdf896-sdl2.ln1@osiris.mauzo.dyndns.org>


Quoth CronJob <spasticgoblin@gmail.com>:
> How do I determine within the program what page I'm on after
> LWP::UserAgent follows a redirect? Is there a way I can determine
> whether redirects has occurred and if so how many redirects were
> followed and what there urls were? (obviously I know what the first
> one was)

See the ->request and ->previous methods of HTTP::Response. ->request
returns the actual request that got this response, so you can get url of
this response with $reponse->request->uri .

Ben



------------------------------

Date: Thu, 19 Mar 2009 11:36:31 +1300
From: Ryan McCoskrie <ryan.mccoskrie@gmail.com>
Subject: Non-textual output
Message-Id: <gprt25$j09$1@news.albasani.net>

I've used perl for odd jobs with I/O before
but it's always been plain text.

How do I get integer 0 instead of integer 48
(ascii 0) into a file?
-- 
Quote of the login: 
Can't open /usr/share/games/fortunes/fortunes. Lid stuck on cookie jar.



------------------------------

Date: Wed, 18 Mar 2009 23:47:05 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Non-textual output
Message-Id: <Xns9BD2C940BDDAAasu1cornelledu@127.0.0.1>

Ryan McCoskrie <ryan.mccoskrie@gmail.com> wrote in news:gprt25$j09$1
@news.albasani.net:

> I've used perl for odd jobs with I/O before
> but it's always been plain text.
> 
> How do I get integer 0 instead of integer 48
> (ascii 0) into a file?

Your question is a little ambiguous because you do not specify what you 
mean by an 'integer'.

I am going to assume you want to get a NUL character written to the 
file.

#!/usr/bin/perl

use strict;
use warnings;

open my $f, '>', 'bin' or die $!;
print $f "a\0b\0c\n";
close $f or die $!;

__END__

C:\DOCUME~1\asu1\LOCALS~1\Temp> xxd bin
0000000: 6100 6200 630d 0a                        a.b.c..

-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


------------------------------

Date: Thu, 19 Mar 2009 00:49:21 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: Non-textual output
Message-Id: <49c18882$0$187$e4fe514c@news.xs4all.nl>

Ryan McCoskrie wrote:

> How do I get integer 0 instead of integer 48
> (ascii 0) into a file?

   chr(0)

-- 
Ruud


------------------------------

Date: Thu, 19 Mar 2009 00:18:58 GMT
From: sln@netherlands.com
Subject: Re: Non-textual output
Message-Id: <up33s4tpd7ej7uika66eh9pqqd0thskp1m@4ax.com>

On Thu, 19 Mar 2009 11:36:31 +1300, Ryan McCoskrie <ryan.mccoskrie@gmail.com> wrote:

>I've used perl for odd jobs with I/O before
>but it's always been plain text.
>
>How do I get integer 0 instead of integer 48
>(ascii 0) into a file?

Sure you say that now, but what happens when you want (ascii -1) into a file?

-sln



------------------------------

Date: Wed, 18 Mar 2009 05:58:17 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: OT on Tomcat and Apache
Message-Id: <07d1a1fc-ad0a-43e5-9c68-afa7c7659ef9@y13g2000yqn.googlegroups.com>

Not totally OT, but close.

Building a new CGI with Perl and mod_perl, I was given a Windows
server that runs (and is running) Tomcat. Rather than configuring
Tomcat to run CGI, I installed Apache 2.2.11, but when I started
Apache I got the following error message:

<error>
(OS 10048)Only one usage of each socket address (protocol/network
address/port)
is normally permitted.  : make_sock: could not bind to address
0.0.0.0:80
no listening sockets available, shutting down
Unable to open logs
Note the errors or messages above, and press the <ESC> key to exit.
</error>

Can I run both Apache and Tomcat on port 80? This machine runs JSP
apps so they need Tomcat.

Does anyone have any experience running Perl scripts with Tomcat?

Where can I get help?

Thanks, CC.


------------------------------

Date: Wed, 18 Mar 2009 08:07:48 -0500
From: Chris Mattern <syscjm@sumire.gwu.edu>
Subject: Re: OT on Tomcat and Apache
Message-Id: <slrngs1sh3.lm3.syscjm@sumire.gwu.edu>

On 2009-03-18, ccc31807 <cartercc@gmail.com> wrote:
> Not totally OT, but close.
>
> Building a new CGI with Perl and mod_perl, I was given a Windows
> server that runs (and is running) Tomcat. Rather than configuring
> Tomcat to run CGI, I installed Apache 2.2.11, but when I started
> Apache I got the following error message:
>
><error>
> (OS 10048)Only one usage of each socket address (protocol/network
> address/port)
> is normally permitted.  : make_sock: could not bind to address
> 0.0.0.0:80
> no listening sockets available, shutting down
> Unable to open logs
> Note the errors or messages above, and press the <ESC> key to exit.
></error>
>
> Can I run both Apache and Tomcat on port 80? This machine runs JSP

No, only one thing at a time can run on port 80.  That's what the
error message is telling you.  If you'll think about it, it makes 
perfect sense.  Assume the machine let you run both Tomcat and Apache
on port 80.  In comes a connection request for port 80 from another
machine.  Who answers: Apache or Tomcat?  There is absolutely no way
to tell.

> apps so they need Tomcat.

Either Apache or Tomcat will need to listen on a port other than 80, with
the applications that use it configured to connect on that port.
>
> Does anyone have any experience running Perl scripts with Tomcat?
>
> Where can I get help?
>
> Thanks, CC.


-- 
             Christopher Mattern

NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities


------------------------------

Date: Wed, 18 Mar 2009 14:59:37 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: OT on Tomcat and Apache
Message-Id: <slrngs1via.hoj.hjp-usenet2@hrunkner.hjp.at>

On 2009-03-18 13:07, Chris Mattern <syscjm@sumire.gwu.edu> wrote:
> On 2009-03-18, ccc31807 <cartercc@gmail.com> wrote:
>> Building a new CGI with Perl and mod_perl, I was given a Windows
>> server that runs (and is running) Tomcat. Rather than configuring
>> Tomcat to run CGI, I installed Apache 2.2.11, but when I started
>> Apache I got the following error message:
>>
>><error>
>> (OS 10048)Only one usage of each socket address (protocol/network
>> address/port)
>> is normally permitted.  : make_sock: could not bind to address
>> 0.0.0.0:80
>> no listening sockets available, shutting down
>> Unable to open logs
>> Note the errors or messages above, and press the <ESC> key to exit.
>></error>
>>
>> Can I run both Apache and Tomcat on port 80? This machine runs JSP
>
> No, only one thing at a time can run on port 80.

That's not quite correct: They can both listen on port 80, *iff* they
listen on different IP addresses. So you could have Tomcat on
192.0.2.1:80 and Apache on 192.0.2.2:80.

> That's what the error message is telling you.  If you'll think about
> it, it makes perfect sense.  Assume the machine let you run both
> Tomcat and Apache on port 80.  In comes a connection request for port
> 80 from another machine.  Who answers: Apache or Tomcat?  There is
> absolutely no way to tell.

Right. Either the IP address or the port number has to differ. 

If you need Apache and Tomcat for the same website, the normal way is
let Apache listen on port 80 and pass requests to Tomcat via mod_jk.
Using a reverse proxy should work, too.

	hp


------------------------------

Date: Wed, 18 Mar 2009 11:35:15 -0700 (PDT)
From: google@markginsburg.com
Subject: Re: Perl Packager - Free to wrong pool error
Message-Id: <0bd49123-0355-4fb7-a205-3bd72d7e020b@v1g2000prd.googlegroups.com>

On Mar 17, 6:53=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth goo...@markginsburg.com:
>
>
>
> > > perl -v
> > This is perl, v5.8.8 built for MSWin32-x86-multi-thread
> > ...
>
> > =3D=3D Begin of test.pl =3D=3D
> > use strict;
> > use warnings;
>
> > my $pid;
>
> > LaunchHostname();
>
> > print "waiting for child $pid to complete...\n";
> > my $waitstat =3D waitpid($pid,0);
> > print "waitpid returned $waitstat\n";
> > exit;
>
> > sub LaunchHostname {
> > =A0 =A0 $pid =3D fork ();
> > =A0 =A0 if (!defined($pid)) {
> > =A0 =A0 =A0 =A0 die "Failed to fork: $!\n";
> > =A0 =A0 }
> > =A0 =A0 elsif ($pid =3D=3D 0) {
> > =A0 =A0 =A0 =A0 # This is the child
> > =A0 =A0 =A0 =A0 exec('hostname.exe'); =A0# LINE 22
> > =A0 =A0 =A0 =A0 die "exec failed\n";
> > =A0 =A0 }
>
> Since you're on Win32, is there a good reason for using fork/exec rather
> than system(1, ...) or Win32::Process? fork on Win32 is a rather
> complicated emulation, and fork+exec ends up being a convoluted way of
> calling spawnvp(3). Since the whole fork API is only present on Win32
> for compatibility with Unix scripts, it's better to use the native
> method.

I was unaware that system() could be made to run asynchroneously.
Thank you for the excellent suggestion, but I don't think it will work
for my situation.

With the fork/exec, I am starting a GUI application and then
manipulating it in my perl code using Win32::GuiTest. This GUI
application MUST be run from a specified directory, so in my actual
perl program, I do a chdir() to that directory in the child process
before the child calls exec() make the child perl process become the
application. I don't think there is any way to do that using system
(1,...).

It is interesting to note that no errors occur when the perl program
is run directly. The errors occur only when I run the executable I've
created using pp.  This makes me suspect that the problem may be
related to something in PAR::Packer.

I was able to work around the problem (in an non-portable way) by
using Win32::Process::Create() instead of fork/exec. Fortunately for
me, Win32::Process::Create() takes the working directory as in input
argument.

> > =A0 =A0 return;
> > }
> > =3D=3D END of test.pl =3D=3D
>
> > > perl test.pl
> > waiting for child -3592 to complete...
> > fileserver123
> > waitpid returned -3592
>
> > > pp -o test.exe test.pl
>
> > > test.exe
> > waiting for child -1600 to complete...
> > fileserver123
> > Free to wrong pool fac720 not 8367c0 at script/test.pl line 22.
>
> 'Free to wrong pool' generally indicates a threading-related bug in
> either perl itself or some XS module. Presumably you can get rid of this
> be removing the fork, but there's still an underlying bug somewhere. A
> lot of these 'Free to wrong pool' bugs were fixed in 5.10, and I expect
> most of the fixes went into 5.8.9 as well.
>
> > When I execute test.exe, the above error message is accompanied by a
> > pop up indicating "test.exe has encountered a problem and needs to
> > close. =A0We are sorry for the inconvenience."
>
> > When I do all the above on a system with perl v5.10.0 installed, I do
> > not get the "Free to wrong pool" message but get a pop up that says:
> > 'The instruction at "0x2800cd70" referenced memory at "0x00000028".
> > The memory could not be "read"'.
>
> > Any ideas why I get these errors?
>
> Not this one, sorry. Can you successfully build and execute anything
> with pp? Can you reduce that test case at all and still provoke the bug?
> Are you able to build a copy of perl with debugging symbols and get a
> stack trace at the point of the crash?
>
> Ben



------------------------------

Date: Wed, 18 Mar 2009 19:47:45 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Perl Packager - Free to wrong pool error
Message-Id: <Xns9BD2A0ACC98CCasu1cornelledu@127.0.0.1>

google@markginsburg.com wrote in news:0bd49123-0355-4fb7-a205-
3bd72d7e020b@v1g2000prd.googlegroups.com:

> With the fork/exec, I am starting a GUI application and then
> manipulating it in my perl code using Win32::GuiTest.

 ...

> I was able to work around the problem (in an non-portable way) by
> using Win32::Process::Create() instead of fork/exec. 

I do not think portability to any other system than Win32 should be a 
concern in this case.

Sinan
-- 
A. Sinan Unur <1usa@llenroc.ude.invalid>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/


------------------------------

Date: Wed, 18 Mar 2009 19:40:05 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Perl Packager - Free to wrong pool error
Message-Id: <l9v796-1mj2.ln1@osiris.mauzo.dyndns.org>


Quoth google@markginsburg.com:
> On Mar 17, 6:53 pm, Ben Morrow <b...@morrow.me.uk> wrote:
> >
> > Since you're on Win32, is there a good reason for using fork/exec rather
> > than system(1, ...) or Win32::Process? fork on Win32 is a rather
> > complicated emulation, and fork+exec ends up being a convoluted way of
> > calling spawnvp(3). Since the whole fork API is only present on Win32
> > for compatibility with Unix scripts, it's better to use the native
> > method.
> 
> I was unaware that system() could be made to run asynchroneously.
> Thank you for the excellent suggestion, but I don't think it will work
> for my situation.
> 
> With the fork/exec, I am starting a GUI application and then
> manipulating it in my perl code using Win32::GuiTest. This GUI
> application MUST be run from a specified directory, so in my actual
> perl program, I do a chdir() to that directory in the child process
> before the child calls exec() make the child perl process become the
> application. I don't think there is any way to do that using system
> (1,...).

Well, the obvious way would be

    use Cwd qw/cwd/;

    my $oldcwd = cwd    or die "can't find cwd: $!";
    chdir "c:/wherever" or die "can't chdir to 'c:/wherever': $!";
    system 1, "command";
    chdir $oldcwd       or die "can't chdir to '$oldcwd': $!";

This of course assumes that you can determine your current directory and
chdir back into it, so if Win32 supports fchdir(2) something like

    opendir my $OLDCWD, "."     or die "can't opendir '.': $!";
    chdir "c:/wherever"         or die "...";
    system 1, "command";
    chdir $OLDCWD;

might be safer (substitute File::Spec->curdir if you like). You can
check if you have fchdir(2) with

    perl -V:d_fchdir

or

    use Config;

    if ($Config{d_fchdir} eq "define") {
        ...
    }

> It is interesting to note that no errors occur when the perl program
> is run directly. The errors occur only when I run the executable I've
> created using pp.  This makes me suspect that the problem may be
> related to something in PAR::Packer.

Yes, me too. I have had numerous problems with pp on Win32 in the past;
the peculiarities of perl and of Win32's dll model combine to mean PAR
has to do some very strange things to get the program to work.
Apparently they don't always work successfully.

> I was able to work around the problem (in an non-portable way) by
> using Win32::Process::Create() instead of fork/exec. Fortunately for
> me, Win32::Process::Create() takes the working directory as in input
> argument.

Yes, whatever you do it will end up calling CreateProcess(2) eventually,
so you might as well call it directly.

Ben



------------------------------

Date: Wed, 18 Mar 2009 22:31:39 GMT
From: sln@netherlands.com
Subject: Re: Perl Packager - Free to wrong pool error
Message-Id: <2ht2s4t2apg75egrm7sago6apq3il8noc7@4ax.com>

On Wed, 18 Mar 2009 19:40:05 +0000, Ben Morrow <ben@morrow.me.uk> wrote:

>
>Quoth google@markginsburg.com:
>> On Mar 17, 6:53 pm, Ben Morrow <b...@morrow.me.uk> wrote:
>> >
>> > Since you're on Win32, is there a good reason for using fork/exec rather
>> > than system(1, ...) or Win32::Process? fork on Win32 is a rather
>> > complicated emulation, and fork+exec ends up being a convoluted way of
>> > calling spawnvp(3). Since the whole fork API is only present on Win32
>> > for compatibility with Unix scripts, it's better to use the native
>> > method.
>> 
>> I was unaware that system() could be made to run asynchroneously.
>> Thank you for the excellent suggestion, but I don't think it will work
>> for my situation.
>> 
>> With the fork/exec, I am starting a GUI application and then
>> manipulating it in my perl code using Win32::GuiTest. This GUI
>> application MUST be run from a specified directory, so in my actual
>> perl program, I do a chdir() to that directory in the child process
>> before the child calls exec() make the child perl process become the
>> application. I don't think there is any way to do that using system
>> (1,...).
>
>Well, the obvious way would be
>
>    use Cwd qw/cwd/;
>
>    my $oldcwd = cwd    or die "can't find cwd: $!";
>    chdir "c:/wherever" or die "can't chdir to 'c:/wherever': $!";
>    system 1, "command";
>    chdir $oldcwd       or die "can't chdir to '$oldcwd': $!";
>
>This of course assumes that you can determine your current directory and
>chdir back into it, so if Win32 supports fchdir(2) something like
>
>    opendir my $OLDCWD, "."     or die "can't opendir '.': $!";
>    chdir "c:/wherever"         or die "...";
>    system 1, "command";
>    chdir $OLDCWD;
>
>might be safer (substitute File::Spec->curdir if you like). You can
>check if you have fchdir(2) with
>
>    perl -V:d_fchdir
>
>or
>
>    use Config;
>
>    if ($Config{d_fchdir} eq "define") {
>        ...
>    }
>
>> It is interesting to note that no errors occur when the perl program
>> is run directly. The errors occur only when I run the executable I've
>> created using pp.  This makes me suspect that the problem may be
>> related to something in PAR::Packer.
>
>Yes, me too. I have had numerous problems with pp on Win32 in the past;
>the peculiarities of perl and of Win32's dll model combine to mean PAR
>has to do some very strange things to get the program to work.
>Apparently they don't always work successfully.
>
>> I was able to work around the problem (in an non-portable way) by
>> using Win32::Process::Create() instead of fork/exec. Fortunately for
>> me, Win32::Process::Create() takes the working directory as in input
>> argument.
>
>Yes, whatever you do it will end up calling CreateProcess(2) eventually,
>so you might as well call it directly.
>
>Ben

Which variable is '2'?

BOOL CreateProcess(
  LPCTSTR lpApplicationName,
  LPTSTR lpCommandLine,
  LPSECURITY_ATTRIBUTES lpProcessAttributes,
  LPSECURITY_ATTRIBUTES lpThreadAttributes,
  BOOL bInheritHandles,
  DWORD dwCreationFlags,
  LPVOID lpEnvironment,
  LPCTSTR lpCurrentDirectory,
  LPSTARTUPINFO lpStartupInfo,
  LPPROCESS_INFORMATION lpProcessInformation
);

-sln


------------------------------

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V11 Issue 2282
***************************************


home help back first fref pref prev next nref lref last post