need to make a perl script work on Linux/Win32 plateforms. - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

need to make a perl script work on Linux/Win32 plateforms.

JoeMcJoeMc Posts: 55Member
Hello All,

I'm new to Windows, been on the dark side (unix/linux) for most of my programming life. Here's my delima, I've written many perl and bash scripts in the past to be executed on unix and linux, and I've also written some, ok a few perl scripts to be executed on Win32 systems. I've also written some bash/perl scripts contianed in the same file where dependent on how you execute it either the perl is executed or the bash is executed. Those command differences were [BASH} <"/usr/bin/bash script">, or [perl] "/usr/bin/perl -x ". I was wondering if I could use one of my "dual" scripts on a Win32 system? Keep in mind all my code in the perl portion would be Win32 compatable. such as using:

if ( $^O eq "linux" || $^O eq "unix" ) {
#Do unix/linux thing...
} else {
#Do Win32 thing...
}

I guess the part I'm confused on (other than my spelling) is would Win32
ignore the bash portion when I execute the perl with "-x" argument?

Thanks in advance for any usful help rendered,
JoeMc

Comments

  • JonathanJonathan Posts: 2,914Member
    Hi,

    : I'm new to Windows, been on the dark side (unix/linux) for most of
    : my programming life.
    You're odd. Most people consider Windows the dark side. :-)

    : Here's my delima, I've written many perl and
    : bash scripts in the past to be executed on unix and linux, and I've
    : also written some, ok a few perl scripts to be executed on Win32
    : systems. I've also written some bash/perl scripts contianed in the
    : same file where dependent on how you execute it either the perl is
    : executed or the bash is executed. Those command differences were
    : [BASH} <"/usr/bin/bash script">, or [perl] "/usr/bin/perl -x ". I was wondering if I could use one of my "dual" scripts on
    : a Win32 system?
    The -x switch works just fine on Windows...in the ActiveState build of Perl it does, anyway, and probably others. Be aware that, at least at the OS level, #! lines are meaningless on Windows though. But your scripts should go on working.

    : Keep in mind all my code in the perl portion would
    : be Win32 compatable. such as using:
    :
    : if ( $^O eq "linux" || $^O eq "unix" ) {
    : #Do unix/linux thing...
    : } else {
    : #Do Win32 thing...
    : }
    Since there are places that the linux stuff would work other than just where $^O is "linux" and "unix", I'd test it like:

    [code]if ($^O ne 'MSWin32') {
    # POSIX thing (unix, linux...)
    } else {
    # Windows things.
    }[/code]

    Hope this helps,

    Jonathan
    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
  • JoeMcJoeMc Posts: 55Member
    : Hi,
    :
    : : I'm new to Windows, been on the dark side (unix/linux) for most of
    : : my programming life.
    : You're odd. Most people consider Windows the dark side. :-)
    :
    : : Here's my delima, I've written many perl and
    : : bash scripts in the past to be executed on unix and linux, and I've
    : : also written some, ok a few perl scripts to be executed on Win32
    : : systems. I've also written some bash/perl scripts contianed in the
    : : same file where dependent on how you execute it either the perl is
    : : executed or the bash is executed. Those command differences were
    : : [BASH} <"/usr/bin/bash script">, or [perl] "/usr/bin/perl -x ". I was wondering if I could use one of my "dual" scripts on
    : : a Win32 system?
    : The -x switch works just fine on Windows...in the ActiveState build
    : of Perl it does, anyway, and probably others. Be aware that, at
    : least at the OS level, #! lines are meaningless on Windows though.
    : But your scripts should go on working.
    :
    : : Keep in mind all my code in the perl portion would
    : : be Win32 compatable. such as using:
    : :
    : : if ( $^O eq "linux" || $^O eq "unix" ) {
    : : #Do unix/linux thing...
    : : } else {
    : : #Do Win32 thing...
    : : }
    : Since there are places that the linux stuff would work other than
    : just where $^O is "linux" and "unix", I'd test it like:
    :
    : [code]: if ($^O ne 'MSWin32') {
    : # POSIX thing (unix, linux...)
    : } else {
    : # Windows things.
    : }[/code]:
    :
    : Hope this helps,
    :
    : Jonathan
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

    Thanks Jonathan,

    So Windows will ignore the bash code and only execute the perl code just like on linux/unix systems when I use the "-x" arg when I run it?

    I actually consider windows the dark side as well, but most windows people I've met seemed a little over senitive to that comment, so I didn't want ruin my chances in getting help. ;-)

    All the Best,
    JoeMc

    By the way...

    Do wouldn't happen to be able to help on another issue as well...?
    I'm trying to figure out how to send a message to a unix port from
    a Win32 plateform in a perl script, most likely a system call.
    I usually execute this netcat command in unix/linux:

    system(`echo "" | nc `);

    Any help would be greatly appreciated.

    -JoeMc
  • JonathanJonathan Posts: 2,914Member
    : So Windows will ignore the bash code and only execute the perl code
    : just like on linux/unix systems when I use the "-x" arg when I run
    : it?
    Yup.

    : I actually consider windows the dark side as well, but most windows
    : people I've met seemed a little over senitive to that comment, so I
    : didn't want ruin my chances in getting help. ;-)
    So what's the light side? VMS? ;-)

    : Do wouldn't happen to be able to help on another issue as well...?
    : I'm trying to figure out how to send a message to a unix port from
    : a Win32 plateform in a perl script, most likely a system call.
    : I usually execute this netcat command in unix/linux:
    :
    : system(`echo "" | nc `);
    :
    : Any help would be greatly appreciated.
    :
    Yeah, I saw that post earlier, though didn't spot that you wanted to do it from a Perl script. Suggest you just do it in Perl using the IO::Socket module perhaps...I don't really know much about networking stuff (well, I kinda do, I just don't really implement that kinda stuff so have to go look it up when I want to do it...) Alternatively I'm sure there is a Win32 port of netcat available.

    Jonathan
    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
  • JoeMcJoeMc Posts: 55Member
    : : So Windows will ignore the bash code and only execute the perl code
    : : just like on linux/unix systems when I use the "-x" arg when I run
    : : it?
    : Yup.
    :
    : : I actually consider windows the dark side as well, but most windows
    : : people I've met seemed a little over senitive to that comment, so I
    : : didn't want ruin my chances in getting help. ;-)
    : So what's the light side? VMS? ;-)

    Pretty much all versions of Unix and flavors of Linux.
    There's also a gray area: all unix/linux simulators that work on windows
    platforms. But once you've seen the light, it hard to go back. ;-)

    :
    : : Do wouldn't happen to be able to help on another issue as well...?
    : : I'm trying to figure out how to send a message to a unix port from
    : : a Win32 plateform in a perl script, most likely a system call.
    : : I usually execute this netcat command in unix/linux:
    : :
    : : system(`echo "" | nc `);
    : :
    : : Any help would be greatly appreciated.
    : :
    : Yeah, I saw that post earlier, though didn't spot that you wanted to
    : do it from a Perl script. Suggest you just do it in Perl using the
    : IO::Socket module perhaps...I don't really know much about
    : networking stuff (well, I kinda do, I just don't really implement
    : that kinda stuff so have to go look it up when I want to do it...)
    : Alternatively I'm sure there is a Win32 port of netcat available.

    I'd love to use netcat on the Win32 server, but I can't figure out how to re-write the first part of the command I was using "echo "" |" so it works on Win32. :-(

    I'll deffinitely look into IO::Socket, thanks for the tip.
    I'll get back to this posting and let you know how it all turns out.

    regards,
    JoeMc

    extra note: what's with the algorithm under your name?
    :
    : Jonathan
    : ###
    : for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    : (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    : /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

  • JonathanJonathan Posts: 2,914Member
    : I'd love to use netcat on the Win32 server, but I can't figure out
    : how to re-write the first part of the command I was using "echo
    : "" |" so it works on Win32. :-(
    The pipe syntax and echo seems to work OK...

    [code]C:Documents and SettingsJonathan>echo badger | perl -ne "print $_ x 3;"
    badger
    badger
    badger[/code]

    What about it wasn't working?

    : extra note: what's with the algorithm under your name?
    Try running it, it's Perl (and harmless). You can also try this one, which I wrote this Christmas just gone:
    http://www.jnthn.net/code/co06.pl

    Yes, I know, I'm sick and evil. :-)

    Jonathan
    ###
    for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
    (tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
    /(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");
Sign In or Register to comment.