Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Platform-independent way of passing cmd-line args.

Reply
Thread Tools

Platform-independent way of passing cmd-line args.

 
 
Prabh
Guest
Posts: n/a
 
      06-21-2004
Hello all,
I need to pass a couple of args to my perl script which are strings of
text.
Arg1: 'one two'
Arg2: 'three four'

Script:
================================================== ==
#!/usr/local/bin/perl

use strict ;
use warnings ;

my $first_arg = $ARGV[0] ;
my $sec_arg = $ARGV[1] ;

print "First: $first_arg\nSecond: $sec_arg\n" ;
================================================== ==


On Unix, when I pass the args as,
<%> perl testArgs.pl 'one two' 'three four'
I get the output,
First: one two
Second: three four

When I try the same script and pass the args in the same way on
Windows, I get,
First: 'one
Second: two'

Its only when I replace the single-quote on the command-line with
double-quotes do I get the same results as Unix.
<%> perl testArgs.pl "one two" "three four"

Is there any platform independent way of passing args which result in
the same
ARGV[0] and ARGV[1] on all platforms?

Perl version: perl v5.6.0

Thanks for your time,
Prabh
 
Reply With Quote
 
 
 
 
Ben Morrow
Guest
Posts: n/a
 
      06-21-2004

Quoth http://www.velocityreviews.com/forums/(E-Mail Removed) (Prabh):
>
> On Unix, when I pass the args as,
> <%> perl testArgs.pl 'one two' 'three four'
> I get the output,
> First: one two
> Second: three four
>
> When I try the same script and pass the args in the same way on
> Windows, I get,
> First: 'one
> Second: two'
>
> Its only when I replace the single-quote on the command-line with
> double-quotes do I get the same results as Unix.
> <%> perl testArgs.pl "one two" "three four"
>
> Is there any platform independent way of passing args which result in
> the same
> ARGV[0] and ARGV[1] on all platforms?


This is not a Perl question: it is a matter of your command shell. If
you use a Unix-ish shell under win32 (cygwin bash, or there is a native
port of zsh available) then single-quotes will work fine.

In general double-quotes are pretty portable, provided you don't need
$, `, \, " or % in the arguments (unix shells will interpret the first
four, DOS/cmd.exe the last two).

Ben

--
Joy and Woe are woven fine,
A Clothing for the Soul divine William Blake
Under every grief and pine 'Auguries of Innocence'
Runs a joy with silken twine. (E-Mail Removed)
 
Reply With Quote
 
 
 
 
Bob Walton
Guest
Posts: n/a
 
      06-21-2004
Prabh wrote:

....
> Is there any platform independent way of passing args which result in
> the same
> ARGV[0] and ARGV[1] on all platforms?



No. Command line argument quoting is a function of the particular
"shell" running on a particular operating system. You only asked about
*nix and Windoze -- on Windoze, you could run Perl under Cygwin, which,
if you use its default bash shell (and, probably, any of the other
shells it provides), will let you quote arguments with ' characters like
*nix. But it will be running on Windoze.

HTH.


....


> Prabh


--
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing parameters to an executable vs. passing them to a server Ramon F Herrera C++ 8 09-13-2009 02:48 AM
passing copy of a pointer to a variable vs passing the copy pereges C Programming 7 06-01-2008 02:36 PM
way way way OT: MCNGP Announcement Neil MCSE 174 04-17-2006 05:55 PM
AMD Opteron: 1-way, 2-way, ... Up to 8-way. John John Windows 64bit 12 12-27-2005 08:17 AM
Passing by const & and returning a temp vs passing by value and returningit Victor Bazarov C++ 25 03-23-2005 04:24 PM



Advertisments