Passing command line arguments

------_=_NextPart_001_01C54075.E7225C28
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

I have a script that is reading input from ARGV.  The script is being
passed a file name as follows:
=20
datefile.pl c:\program files\IBM\SQLLIB\DB2\db2diag.log
=20
The problem I am running into is that the space is not recognized in the
argument.  All that I get passed to is is c:\program    .  How do I get
the rest of the argument.  Below is a portion of the script.  Thanks.
=20
 #***********************************************
 # check input parameter                        *
 #***********************************************
 $arg_length =3D length($ARGV[0]);
 $arg_lastchar =3D substr($ARGV[0], $arg_length-1, 1);
 $arg_string =3D $ARGV[0] ;
 print "Parameter argument is: $arg_string \n";


------_=_NextPart_001_01C54075.E7225C28--
0
Bret
4/13/2005 10:12:38 PM
perl.beginners 29388 articles. 4 followers. Follow

5 Replies
598 Views

Similar Articles

[PageSpeed] 41
Get it on Google Play
Get it on Apple App Store

Subject: Passing command line arguments

I have a script that is reading input from ARGV.  The script is being
passed a file name as follows:
 
datefile.pl c:\program files\IBM\SQLLIB\DB2\db2diag.log
 
The problem I am running into is that the space is not recognized in the
argument.  All that I get passed to is is c:\program    .  How do I get
the rest of the argument.  Below is a portion of the script.  Thanks.
 
 #***********************************************
 # check input parameter                        *
 #***********************************************
 $arg_length = length($ARGV[0]);
 $arg_lastchar = substr($ARGV[0], $arg_length-1, 1);
 $arg_string = $ARGV[0] ;
 print "Parameter argument is: $arg_string \n";


SUN1-BATCH>./foo "1 2 3" 4 5 6
Number of parameters = <4>
1 2 3
SUN1-BATCH>more foo
#!/usr/bin/perl
print "Number of parameters = <" . scalar(@ARGV) . ">\n" if (scalar(@ARGV));
print $ARGV[0], "\n";
SUN1-BATCH>

Hope this gives you some ideas...

jwm
0
john
4/13/2005 10:18:17 PM
On Wednesday 13 April 2005 11:12 pm, Bret Goodfellow wrote:
> I have a script that is reading input from ARGV.  The script is being
> passed a file name as follows:
>
> datefile.pl c:\program files\IBM\SQLLIB\DB2\db2diag.log

You could paste the two arguments together in perl, add
a space between them, and use that as the filename.

Or you could just quote the argument:
datefile.pl "c:\program files\IBM\SQLLIB\DB2\db2diag.log"
0
s
4/14/2005 7:17:03 PM
Stephen Day wrote:
> On Wednesday 13 April 2005 11:12 pm, Bret Goodfellow wrote:
> 
>>I have a script that is reading input from ARGV.  The script is being
>>passed a file name as follows:
>>
>>datefile.pl c:\program files\IBM\SQLLIB\DB2\db2diag.log
> 
> You could paste the two arguments together in perl, add
> a space between them, and use that as the filename.

What if there are two or more spaces?  A TAB character?


John
-- 
use Perl;
program
fulfillment
0
krahnj
4/14/2005 11:18:28 PM
On Friday 15 April 2005 12:18 am, John W. Krahn wrote:

> >>datefile.pl c:\program files\IBM\SQLLIB\DB2\db2diag.log
> >
> > You could paste the two arguments together in perl, add
> > a space between them, and use that as the filename.
>
> What if there are two or more spaces?  A TAB character?

Then it would totally mess up.

I was trying to say you could do a complex thing, but it's
better to just quote the argument and not face the problem
in the first place.
0
s
4/14/2005 11:32:50 PM
On 4/13/05, Bret Goodfellow <Bret.Goodfellow@questar.com> wrote:
> I have a script that is reading input from ARGV.  The script is being
> passed a file name as follows:
>=20
> datefile.pl c:\program files\IBM\SQLLIB\DB2\db2diag.log
>=20
> The problem I am running into is that the space is not recognized in the
> argument.  All that I get passed to is is c:\program    .  How do I get
> the rest of the argument.  Below is a portion of the script.  Thanks.
>=20
>  #***********************************************
>  # check input parameter                        *
>  #***********************************************
>  $arg_length =3D length($ARGV[0]);
>  $arg_lastchar =3D substr($ARGV[0], $arg_length-1, 1);
>  $arg_string =3D $ARGV[0] ;
>  print "Parameter argument is: $arg_string \n";
>=20
>=20

This is really an OS question, not a perl question: you'd have this
problem with any language, including, I think the built-in windows
shell interpreter--but that's another issue.  Most OSes and/or shells
have some method of escaping characters.  in most unix environments,
you'd handle this by using single quotes on the command line:
datefile.pl '/path/to/file'.  I'm not sure how windows handles it
(Ithink double and singe quotes may have the opposite meanings), and
it might vary between 95 and NT/2000/XP.  Try both of the following,
one of them will work:

datefile.pl 'c:\program files\IBM\SQLLIB\DB2\db2diag.log'
datefile.pl "c:\program files\IBM\SQLLIB\DB2\db2diag.log"

If you're going to be be doing a lot of work on Windows, take a look
at perldoc perlport, and pick up a copy of _Learning Perl for Win32_

HTH,

--jay
0
daggerquill
4/14/2005 11:37:41 PM
Reply:

Similar Artilces:

How to pass command line arguments to an extension using a command line on MacOS?
I am developing an extension that processes some command line options. I want to invoke the Firefox from a command line like this: > ...../firefox -myarg1 -myarg2 I am running into a problem on Mac OS. When I run such command when there is no FireFox running it works fine. However if I run the command again I get an error saying that there is already an instance of Firefox running and only one instance can run at a time (paraphrasing here). I have tried to use the -remote option but no luck. Does anyone know how to solve this problem? Does anyone know if invoking of chatzill...

How to pass command line arguments to an extension using a command line on MacOS
I am developing an extension that processes some command line options. I want to invoke the Firefox from a command line like this: > ...../firefox -myarg1 -myarg2 I am running into a problem on Mac OS. When I run such command when there is no FireFox running it works fine. However if I run the command again I get an error saying that there is already an instance of Firefox running and only one instance can run at a time (paraphrasing here). I have tried to use the -remote option but no luck. Does anyone know how to solve this problem? Does anyone know if invoking of chatzill...

How to pass string in command line argument.
------=_Part_34745_22223991.1161859678592 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline hi , I want to pass a command argument to perl script with double quotes (" ); below is my scenario my xml file is something like this .. <root> <reff> <var1>123</var1> <var2>this is my name</var2> </reff> <reff> <var1>234</var1> <var2>this is others name </var2> </reff> </root> my perl script...

Passing command line arguments to a XUL application? How?
I have an application which is started on client hosts using "firefox -chrome chrome://idesk/chrome". I am looking for a solution to pass an additional URL as argument to the application where the application get some further UI informations from. This since URL is specific to the client I can not hard-code the URL into the XUL application. I played with reading the information from a local configuration file in the file-system (which works) but the client application can run on any operating system and being installed in any location..so there is no fixed location I can...

Passing table name as (command line) argument
Any way to pass the name of a table to be processed via an argument either from a command line or in a composite report. We have several tables that are processed by otherwise identical reports/cross-tabs. Rick; If you have PowerBuilder at your site you could do it by: 1) In PB, create a global function(GF). In that function, use the "GetContextKeywords" method to access DOS environment variables. Return a "String" of the DOS variable you wish to locate. 2) In PB, modify the report Window class in the IMStyle.pbl library that IM uses to build the E...

Passing data arguments via command line
Sorry, let's try that again with a sensible subject line -- Mo ======== Hi all, This is a very dim question, but hey, this is a beginners' list so I hope you'll forgive me. I want to be able to pass variable data arguments to my perl script from an outside application by calling a command line that's something along the lines of: perl myscript.pl "data1" "data2 "data3" (a) is it possible to pass data arguments via the command line in this way? (b) inside the script I want to assign them to variables -- but how do I reference...

Can I pass dynamic command-line arguments?
Is there a way to pass dynamic command-line arguments when I run the .wdk file? Shoshana Kalson ...

Passing command line arguments to XUL application
Hi all, I am new to XUL. I am trying to port a MFC web application to XUL. I have gone through the tutorial for creating XUL-based browser application (launched with XULRunner.exe) without using any C++ code. All the code is in JavaScript. One problem I am having is to retrieve the command line arguments that I pass to the XUL application. In the MFC version, I would execute something like: myApp.exe -x 200 -y 400 -z "long string argument" So in my XUL-based application I tried the following: XULRunner.exe myApp -x 200 -y 400 -z "long string arg...

How to pass 2 command arguments for a single command?
Hi I need 2 command arguments for edit . I tried to Pass like CommandArgument='<%# Eval("Path") +'|'+Eval("imageTypeId") this and in the .csstring arg = Convert.ToString(e.CommandArgument); Response.Write(arg);string[] splitarg = arg.Split('|'); Response.Write(splitarg[0]); Its not working. can anyone help me?  I'm using XmlDatasource try this CommandArgument='<%# XPath("Name").ToString() + "|" + XPath("Name").ToString()%>' Hosam Kamel Remember to click on Mark as answer on the p...

command line arguments
Hi, Does anyone know how to give command line arguments while running a powerbuilder application using pbls in pb 8.0 Note: I am not asking about executable but running application in pb IDE by clicking on RUN option. VB has such an option. -- Regards, Shashank J Karulkar. -- Regards, Shashank J Karulkar. Please don't cross-post. On Fri, 14 Mar 2003 10:54:37 +0530, "Shashank J Karulkar" <shanky_17@hotmail.com> wrote: > >Hi, > >Does anyone know how to give command line arguments >while running a powerbuilder application us...

command line arguments
This script gives me nothing: #!/usr/bin/perl -F/\t/ -ap print @F[14 .. 17] if $F[0] eq "H" and $F[5] = 1816; print @F[14 .. 17] if $F[0] eq "H" and $F[5] = 5380; print @F[14 .. 17] if $F[0] eq "H" and $F[5] = 5370; The file is indeed tab delimited, and the sixth field should have a number in it the line starts with a 'H'. When I run this script in debug mode, there is nothing in the array @F. version of perl: 5.003 (upgrade is not a consideration right now... :-( ) ABhagwandin@STSSystems.com wrote: > > This script gives me no...

Command Line arguments
I am new to Power++ so it could be a rather silly question.... In my application I would like to read the number of command line arguments and the arguments itself, ie like argc and argv of typical C programs. Sunitha http://www.orbit.org/power/n_november97.html#11 Check out the above link... Hope this helps Pat Sunitha Chamarti wrote in message <35EDB5E7.820559FB@sybase.com>... >I am new to Power++ so it could be a rather silly question.... > >In my application I would like to read the number of command line >arguments and the arguments itself, ie l...

Command line arguments
Hi, I am searching a list of ALL FF Command line arguments like http://kb.mozillazine.org/Command_line_arguments but complete. Greg Gr�goire Berclaz wrote: > Hi, > > I am searching a list of ALL FF Command line arguments like > http://kb.mozillazine.org/Command_line_arguments but complete. > > Greg > > in window, probably "firefox.exe" -help will list all available command lines. It don't work "Nir" <nir.sen@hotmail.com> a �crit dans le message de news: 5aydnUyBMdPcPBvYnZ2dnUVZ_tHinZ2d@mozilla.org......

Command Line arguments.
Hi guys, Can anyone tell me how can I take the command line arguments in a perl script . I forgot how to do it . Thanks for your support . Regards, Nick The command-line arguments are stored in the built-in @ARGV array. Therefore, if you say something like : perl sample.pl argument1 argument2 argument3 then in your program you can access each of the command-line arguments as follows print $ARGV[0]; #prints argument1 print $ARGV[1]; #prints argument2 etc -- Rex > -----Original Message----- > From: Nicolae Popovici [mailto:np@ipc-fabautomation.com] >...

Web resources about - Passing command line arguments - perl.beginners

Argument (linguistics) - Wikipedia, the free encyclopedia
In linguistics , an argument is an expression that helps complete the meaning of a predicate . Most predicates take one, two, or three arguments. ...

Brexit? David Cameron outlines arguments for UK EU referendum
WHEN UK Prime Minister David Cameron stepped up to the microphone last week, he was in no mood to beat around the bush.

Parliament chaos over Bates moonlighting argument
Jarrod Bleijie has slammed Health Minister Cameron Dick as being &quot;so up yourself&quot; as the Queensland Parliament erupted into chaos following ...

Every argument against automatic voter registration, debunked
... would inconvenience citizens and waste government resources for no justifiable reason.” But these claims, along with all of the other arguments ...

There's a name for this argument Debbie Wasserman Schultz is making about Hillary Clinton's story of ...
It's "fake but accurate." Watch the video of Andrea Mitchell pushing for an explanation for why Hillary is going around making this claim that's ...

The White House's top spokesman had an intense argument with a Fox News host over the Paris attack
... said. "He called this a 'setback.' Why? Just a 'setback' seems cavalier. But go ahead and answer the question." Earnest repeated his argument ...

Pro-Hillary Mayor Makes The Most Shocking Argument Yet For Denying Syrian Refugees
Pro-Hillary Mayor Makes The Most Shocking Argument Yet For Denying Syrian Refugees

Let's have an argument about encryption
Government officials have been vexed for quite some time now that they can't surveil communications that use end-to-end encryption. Never mind ...

Arguments to Justify a Delayed Claiming Age for Social Security
... to develop a Social Security claiming strategy. When should you apply for benefits? Disagreement exists on this topic, and I will review arguments ...

US, China officials get into heated argument over Tibet
US, China officials get into heated argument over Tibet

resources last updated: 11/20/2015 1:35:57 PM