Re: Running the same perl script on Win32 and Unix
- From: rob.dixon@xxxxxxx (Rob Dixon)
- Date: Thu, 07 Sep 2006 12:56:44 +0100
Mahdi A Sbeih wrote:
> Hi there,
>
> I have a perl script that will run on both Unix and Windows platforms,
> the only problem I am having is below:
>
> use Win32::Process;
>
> I have to use the above only for windows since later in my script:
> if ($platform eq 'UNIX') {
> system("$Cmd > /dev/null 2>&1 &");
> }
> elsif ($platform eq 'WINDOWS') {
> Win32::Process::Create($process,"$^X","$^X" . " $Cmd",0,
> CREATE_NO_WINDOW, ".") || die $!;
> }
>
>
> I don't want to maintain two scripts, and it seems I cann't do something
> like this on the top of the script:
> if ($platform eq 'WINDOWS') {
> use Win32::Process;
> }
>
>
> Anyone can help?
>
> NOTE: regarding the above platform variable, it is defined on the top of
> the script:
> ($^O =~ /Win32/) ? ($platform = 'WINDOWS') : ($platform = 'UNIX');
Hello Mahdi (have I picked the right first name?)
A call to 'use' can't be put within a conditional, but one to 'require' can.
Simply replace
use Win32::Process;
with
BEGIN {
if ($^O eq 'MSWin32') {
require Win32::Process;
Win32::Process->import;
}
}
and you should be fine.
HTH,
Rob
.
- Follow-Ups:
- Re: Running the same perl script on Win32 and Unix
- From: Mahdi A Sbeih
- Re: Running the same perl script on Win32 and Unix
- References:
- Running the same perl script on Win32 and Unix
- From: Mahdi A Sbeih
- Running the same perl script on Win32 and Unix
- Prev by Date: hash key not found .. WHY NOT?
- Next by Date: Re: hash key not found .. WHY NOT?
- Previous by thread: Re: Running the same perl script on Win32 and Unix
- Next by thread: Re: Running the same perl script on Win32 and Unix
- Index(es):
Relevant Pages
|