Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This is a perlrun Windows question.

On our network, I provide users with several ways to use perl scripts. The most popular method among Windows users has been to convert the script to a batch file, launched with a shortcut on the desktop. The user can then drag an icon or group of icons onto the shortcut, which provides the script with the argument list of files or folders for the operation.

In several of the more complicated scripts, I use Getopt::Long for parsing the options. But, I have discovered that NT4 and Win9x do not properly handle the options, using this method. When the shortcut is launched without arguments, the options are parsed normally. But if the argument list is provided by dropping file or folder icons onto the shortcut, the options are silently ignored.

Options are parsed as expected in Windows 2000 and XP.

My question: Do you know of a way to cause NT4 and Win9x shortcuts to behave the same as Windows 2000?

A little test script follows the READMORE tag, if you have opportunity to try it for yourself.

@rem = '--*-Perl-*-- @echo off if "%OS%" == "Windows_NT" goto WinNT perl -x -S "%0" %1 %2 %3 %4 %5 %6 %7 %8 %9 goto endofperl :WinNT perl -x -S %0 %* if NOT "%COMSPEC%" == "%SystemRoot%\system32\cmd.exe" goto endofperl if %errorlevel% == 9009 echo You do not have Perl in your PATH. if errorlevel 1 goto script_failed_so_exit_with_non_zero_val 2>nul goto endofperl @rem '; #!/usr/bin/perl -w #line 15 #testprob.bat use strict; use Getopt::Long; # Print Argument list prior to calling GetOptions print STDERR join("|", @ARGV), "\n"; my $always = ''; my $col = -1; my $recursive = ''; my $verbose = 0; print STDERR "(GetOptions called here)\n"; GetOptions ('always!' => \$always, 'recursive!' => \$recursive, 'col=i' => \$col, 'verbose!' => \$verbose); # Print Argument list after calling GetOptions print STDERR join("|", @ARGV), "\n"; wait_close("Process completed\n",4); sub wait_close{ my ($warning, $timer) = @_; $timer = int($timer) || 2; my $i; print "$warning\n"; for ($i=$timer; $i >= 1; $i--){ print "window will close in $i \r"; sleep 1; } exit; } __END__ :endofperl

In the shortcut to the batchfile, the commandline looks like this:

\\netshare\testprob.bat --noalways -v -c=3 --recursive

On all Windows versions tested, the output without an argument list is:
--noalways|-v|-c=3|--recursive
(GetOptions is here)

Process completed

Now, dropping a list of icons onto the shortcut, versions behave differently
Windows 2000 and XP:

--noalways|-v|-c=3|--recursive|C:\c-media|C:\bin|C:\bats
(GetOptions is here)
C:\c-media|C:\bin|C:\bats
Process completed


NT4 and Win9x:
C:\c-media|C:\bin|C:\bats
(GetOptions is here)
C:\c-media|C:\bin|C:\bats
Process completed

Note that the options list is never seen by the script. Options are deleted by Windows, and only the argument list is presented to the script.

Can NT4 and Win9x shortcuts be caused to behave the same as Windows 2000?
mkmcconn
edit format and removed typo noticed by BrowserUK


In reply to Getopts with NT4 and Win9x shortcuts by mkmcconn

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 13:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found