how to use shebang with @ARGV?

Discussion in 'Perl Misc' started by Mark_Galeck, Aug 15, 2009.

  1. Mark_Galeck

    Mark_Galeck Guest

    Look at foobar.pl: (on WinXP and Strawberry Perl)

    #!perl
    print $#ARGV + 1 . " command-line arguments.\n";


    D:\Perl>perl foobar.pl 1 1
    2 command-line arguments.

    D:\Perl>foobar.pl 1 1
    0 command-line arguments.



    Why is this so? How can I use @ARGV and shebang?

    Thank you for your insights! Mark
     
    Mark_Galeck, Aug 15, 2009
    #1
    1. Advertising

  2. body { font: Helvetica, Arial, sans-serif; } p { font: Helvetica, Arial, sans-serif; } ..standout { font-family: verdana, arial, sans-serif; font-size: 12px; color: #993333; line-height: 13px; font-weight: bold; margin-bottom: 10px; } ..code { border-top: 1px solid #ddd; border-left: 1px solid #ddd; border-right: 2px solid #000; border-bottom: 2px solid #000; padding: 10px; margin-top: 5px; margin-left: 5%; margin-right: 5%; background: #ffffea; color: black; -moz-border-radius: 10px; } ..codedark { border-top: 10px solid #03f; border-left: 1px solid #ddd; border-right: 2px solid grey; border-bottom: 2px solid grey; padding: 10px; margin-top: 5px; margin-left: 5%; margin-right: 5%; background: black; color: yellow; -moz-border-radius: 10px; } #code { color: black; font-size: 14px; font-family: courier; padding-left: 5px; } #line-number { color: #804000; font-family: Arial; font-size: 14px; padding-right: 5px; border-right: 1px dotted #804000; } blockquote[type=cite] { padding: 0em .5em .5em .5em !important; border-right: 2px solid blue !important; border-left: 2px solid blue !important; } blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid maroon !important; border-left: 2px solid maroon !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid teal !important; border-left: 2px solid teal !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid purple !important; border-left: 2px solid purple !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid green !important; border-left: 2px solid green !important; } Mark_Galeck wrote:

    Look at foobar.pl: (on WinXP and Strawberry Perl) #!perl print $#ARGV + 1 . " command-line arguments.\n"; D:\Perl>perl foobar.pl 1 1 2 command-line arguments. D:\Perl>foobar.pl 1 1 0 command-line arguments. Why is this so? How can I use @ARGV and shebang? Thank you for your insights! Mark

    What makes you think that Windows cares about shebang?


    --
    Andrew DeFaria
    Don't bother me. I'm living happily ever after.
     
    Andrew DeFaria, Aug 15, 2009
    #2
    1. Advertising

  3. Mark_Galeck

    Mark_Galeck Guest

    >What makes you think that Windows cares about shebang?--Andrew DeFaria

    That #!perl works at all.
     
    Mark_Galeck, Aug 15, 2009
    #3
  4. body { font: Helvetica, Arial, sans-serif; } p { font: Helvetica, Arial, sans-serif; } ..standout { font-family: verdana, arial, sans-serif; font-size: 12px; color: #993333; line-height: 13px; font-weight: bold; margin-bottom: 10px; } ..code { border-top: 1px solid #ddd; border-left: 1px solid #ddd; border-right: 2px solid #000; border-bottom: 2px solid #000; padding: 10px; margin-top: 5px; margin-left: 5%; margin-right: 5%; background: #ffffea; color: black; -moz-border-radius: 10px; } ..codedark { border-top: 10px solid #03f; border-left: 1px solid #ddd; border-right: 2px solid grey; border-bottom: 2px solid grey; padding: 10px; margin-top: 5px; margin-left: 5%; margin-right: 5%; background: black; color: yellow; -moz-border-radius: 10px; } #code { color: black; font-size: 14px; font-family: courier; padding-left: 5px; } #line-number { color: #804000; font-family: Arial; font-size: 14px; padding-right: 5px; border-right: 1px dotted #804000; } blockquote[type=cite] { padding: 0em .5em .5em .5em !important; border-right: 2px solid blue !important; border-left: 2px solid blue !important; } blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid maroon !important; border-left: 2px solid maroon !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid teal !important; border-left: 2px solid teal !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid purple !important; border-left: 2px solid purple !important; } blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] blockquote[type=cite] { border-right: 2px solid green !important; border-left: 2px solid green !important; } Mark_Galeck wrote: What makes you think that Windows cares about shebang?--Andrew DeFaria
    That #!perl works at all.
    #!perl doesn't work at all in Windows. You must have a file association for .pl files. Try this. Rename that file to remove it's .pl extension - let's call it say mark_galeck - no extension at all. Then try running it. My bet would be that it doesn't run at all.

    So then your Perl script is not being exec(1)'ed in the "standard" way thus I would not expect it to behave in a standard fashion.

    Another test: take your Perl script to a Unix system. Bet it works there. That's because a true exec(1) is being used.


    --
    Andrew DeFaria
    Make it idiot proof and someone will make a better idiot.
     
    Andrew DeFaria, Aug 15, 2009
    #4
  5. Mark_Galeck

    Mark_Galeck Guest

    Thank you Andrew.
     
    Mark_Galeck, Aug 15, 2009
    #5
  6. Mark_Galeck

    fred Guest

    On Aug 15, 6:27 am, Mark_Galeck <>
    wrote:
    > Look at foobar.pl: (on WinXP and Strawberry Perl)
    >
    > #!perl
    > print $#ARGV + 1  . " command-line arguments.\n";
    >
    > D:\Perl>perl foobar.pl 1 1
    > 2 command-line arguments.
    >
    > D:\Perl>foobar.pl 1 1
    > 0 command-line arguments.
    >
    > Why is this so?  How can I use @ARGV and shebang?
    >
    > Thank you for your insights!  Mark



    The #! line is not used by Windows to find the interpreter.
    On Windows you need to associate the ".pl" file extension
    with your perl.exe which your 2nd example shows you've done.

    The problem you have shown is that the command line arguments
    are not being passed to the interpreter.

    Fire up regedit, and find the key:

    HKEY_CLASSES_ROOT\Applications\perl5.10.0.exe\shell\open\command

    (yours might be for perl.exe or perl5.8.7.exe etc.)

    It needs to be of the form:

    "C:\strawberry\perl\bin\perl5.10.0.exe" "%1" %*

    (obviously you'll need to use the path to your perl.exe :)

    It's the "%*" that represents the comand line arguments that
    get passed to the interpreter.

    Additionally, you may want to add ".pl" to your PATHEXT environment
    variable so that you can then run "foobar" rather than "foobar.pl";
    and by adding the directory containnig foobar.pl to your PATH you
    will be able to run it as "foobar" from any directory.

    HTH.
     
    fred, Aug 15, 2009
    #6
  7. Mark_Galeck

    Guest

    On Sat, 15 Aug 2009 00:14:58 -0700 (PDT), fred <> wrote:

    >On Aug 15, 6:27 am, Mark_Galeck <>
    >wrote:
    >> Look at foobar.pl: (on WinXP and Strawberry Perl)
    >>
    >> #!perl
    >> print $#ARGV + 1  . " command-line arguments.\n";
    >>
    >> D:\Perl>perl foobar.pl 1 1
    >> 2 command-line arguments.
    >>
    >> D:\Perl>foobar.pl 1 1
    >> 0 command-line arguments.
    >>
    >> Why is this so?  How can I use @ARGV and shebang?
    >>
    >> Thank you for your insights!  Mark

    >
    >
    >The #! line is not used by Windows to find the interpreter.
    >On Windows you need to associate the ".pl" file extension
    >with your perl.exe which your 2nd example shows you've done.
    >
    >The problem you have shown is that the command line arguments
    >are not being passed to the interpreter.
    >
    >Fire up regedit, and find the key:
    >
    >HKEY_CLASSES_ROOT\Applications\perl5.10.0.exe\shell\open\command
    >
    >(yours might be for perl.exe or perl5.8.7.exe etc.)
    >
    >It needs to be of the form:
    >
    >"C:\strawberry\perl\bin\perl5.10.0.exe" "%1" %*
    >
    >(obviously you'll need to use the path to your perl.exe :)
    >
    >It's the "%*" that represents the comand line arguments that
    >get passed to the interpreter.
    >
    >Additionally, you may want to add ".pl" to your PATHEXT environment
    >variable so that you can then run "foobar" rather than "foobar.pl";
    >and by adding the directory containnig foobar.pl to your PATH you
    >will be able to run it as "foobar" from any directory.
    >
    >HTH.
    >


    Checklist:
    1. Add association file extension .pl "%1" %*
    2. Add .pl to PATHEXT (now an executable)
    3. Add directory to PATH
    4. Open a cmd window, type perl foobar
    5. Double click .pl file from explorer to edit

    Very nice, no confusion whatsoever.
    -sln
     
    , Aug 16, 2009
    #7
  8. Mark_Galeck

    Mark_Galeck Guest

    thank you everybody, this is great, I have another rather silly (I am
    sure) question about sockets, in a moment
     
    Mark_Galeck, Aug 16, 2009
    #8
  9. Mark_Galeck

    Guest

    On Sat, 15 Aug 2009 22:14:02 -0700 (PDT), Mark_Galeck <> wrote:

    >
    >
    >thank you everybody, this is great, I have another rather silly (I am
    >sure) question about sockets, in a moment


    Hey I got a socket question for you. Besides handshaking, what layers
    if any do you send packetised over the connection. Do you ever do
    private socket talk?

    -sln
     
    , Aug 16, 2009
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bret

    char **argv vs. char* argv[]

    Bret, Aug 31, 2003, in forum: C Programming
    Replies:
    21
    Views:
    4,635
    Richard Heathfield
    Sep 3, 2003
  2. David
    Replies:
    10
    Views:
    6,013
    Richard Heathfield
    Sep 15, 2003
  3. Hal Styli
    Replies:
    14
    Views:
    1,686
    Old Wolf
    Jan 20, 2004
  4. =?ISO-8859-1?Q?Thomas_N=FCcker?=

    sys.argv[0] - 'module' object has no attribute 'argv'

    =?ISO-8859-1?Q?Thomas_N=FCcker?=, Jun 30, 2003, in forum: Python
    Replies:
    0
    Views:
    944
    =?ISO-8859-1?Q?Thomas_N=FCcker?=
    Jun 30, 2003
  5. jab3

    char **argv & char *argv[]

    jab3, Dec 4, 2004, in forum: C Programming
    Replies:
    5
    Views:
    682
    Chris Torek
    Dec 8, 2004
Loading...

Share This Page