<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>eTechTips &#187; Programming</title>
	<atom:link href="http://www.etechtips.com/articles/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.etechtips.com</link>
	<description>Your Technical resource</description>
	<lastBuildDate>Wed, 01 Feb 2012 21:38:57 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Python: error when using the input() function</title>
		<link>http://www.etechtips.com/2012/01/20/python-error-when-using-the-input-function/</link>
		<comments>http://www.etechtips.com/2012/01/20/python-error-when-using-the-input-function/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 17:38:24 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=610</guid>
		<description><![CDATA[I was writing a basic guessing game and when I tried to take user input I was getting the following: Code: guess = input() d Error: Traceback (most recent call last): File "", line 1, in File "", line 1, in NameError: name 'd' is not defined The problem is actually with the version of [...]]]></description>
			<content:encoded><![CDATA[<p>I was writing a basic guessing game and when I tried to take user input I was<br />
getting the following:</p>
<p>Code:</p>
<pre>
guess = input()
d
</pre>
<p>Error:</p>
<pre>
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1, in <module>
NameError: name 'd' is not defined
</pre>
<p>The problem is actually with the version of Python that I was using.  If you<br />
are using Python 2.x, you need to use the raw_input() function. And with 3.x<br />
you can use the input() function.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2012/01/20/python-error-when-using-the-input-function/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python: if/else Statements</title>
		<link>http://www.etechtips.com/2012/01/20/python-ifelse-statements/</link>
		<comments>http://www.etechtips.com/2012/01/20/python-ifelse-statements/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 16:25:47 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=601</guid>
		<description><![CDATA[There comes a time when you are writing a program and you need to branch based on input to a program. This is the format of the if/else statement in Python. if &#60;some true/false statement&#62; : &#60;some statements that run if the if statement is true&#62; else: &#60;some other statements that run if the if [...]]]></description>
			<content:encoded><![CDATA[<p>There comes a time when you are writing a program and you need to branch based on input to a program.<br />
This is the format of the if/else statement in Python.  </p>
<pre>
if &lt;some true/false statement&gt; :
  &lt;some statements that run if the if statement is true&gt;
else:
  &lt;some other statements that run if the if statement are false&gt;
</pre>
<p>There may be times when you have more than one value set to test against.  In that case you can write a many if/else<br />
statements but you can chain the if/else statements with an elif.  So the chain becomes if/elif/else.</p>
<pre>
if x < 5:
  &lt;some statements that run if the if statement is true&gt;
elif x > 5 and x < 10:
  &lt;some statements that run if the elif statement is true&gt;
else:
  &lt;if none of the if checks are true, run the statements in the else case.&gt;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2012/01/20/python-ifelse-statements/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Python: Allow for empty if else blocks</title>
		<link>http://www.etechtips.com/2012/01/20/python-allow-for-empty-if-else-blocks/</link>
		<comments>http://www.etechtips.com/2012/01/20/python-allow-for-empty-if-else-blocks/#comments</comments>
		<pubDate>Fri, 20 Jan 2012 16:15:28 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=605</guid>
		<description><![CDATA[I was toying with a prime number finder and was creating a set of if/else statements for a horribly failed attempt and wanted to skip to the next number on any of the if statements that were true. I didn&#8217;t want to put an empty print statement as that would disrupt the output I was [...]]]></description>
			<content:encoded><![CDATA[<p>I was toying with a prime number finder and was creating a set of if/else statements for a horribly failed attempt<br />
and wanted to skip to the next number on any of the if statements that were true.  I didn&#8217;t want to put an empty print<br />
statement as that would disrupt the output I was expecting from the program.  I found the pass statement.<br />
Here is an example from my not very successful attempt at finding primes:</p>
<pre>
if inp > 2 and inp % 2 == 0:
  pass
elif inp > 3 and inp % 3 == 0:
  pass
elif inp > 7 and inp % 7 == 0:
  pass
elif inp > 9 and inp % 9 == 0:
  pass
else:
  print inp, " is a prime"
</pre>
<p>Yes, this does not accurately find the primes, but it would skip any number that is divisible by 2,3,5,7, or 9.  And<br />
anything that does not match this will be listed as a prime, this is incorrect and would be made to add new elif<br />
statements as each prime was found.   </p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2012/01/20/python-allow-for-empty-if-else-blocks/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C: Check if string is a number</title>
		<link>http://www.etechtips.com/2012/01/10/c-check-if-string-is-a-number/</link>
		<comments>http://www.etechtips.com/2012/01/10/c-check-if-string-is-a-number/#comments</comments>
		<pubDate>Tue, 10 Jan 2012 16:04:44 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=595</guid>
		<description><![CDATA[I was recently testing some basic input and wrote this code to test if the input was a number or not. #include int main() { char name[10]; scanf("%s",&#038;name); if (checkifNumber(name)) { printf("Is a number\n"); } else { printf("Invalid number\n"); } } int checkifNumber(char *inp) { int i=0; int isanumber = 1; while(inp[i] != '\0' &#038;&#038; [...]]]></description>
			<content:encoded><![CDATA[<p>I was recently testing some basic input and wrote this code to test if the input was a number or not.</p>
<pre>
#include <stdio.h>

int main()
{
  char name[10];

  scanf("%s",&#038;name);
  if (checkifNumber(name))
  {
     printf("Is a number\n");
  }
  else
  {
     printf("Invalid number\n");
  }
}

int checkifNumber(char *inp)
{
  int i=0;
  int isanumber = 1;

  while(inp[i] != '\0' &#038;&#038; i < 10)
  {
    if (inp[i] >= '0' &#038;&#038; inp[i] <= '9')
    {
    }
    else
    {
      isanumber =0;
    }
    i++;
  }
  return isanumber;
}
</pre>
<p>One thing that could be improved is to potentially use a global variable to define the length of the<br />
input string as it is used in two different places in the program and could potentially lead to an<br />
array overrun/underrun.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2012/01/10/c-check-if-string-is-a-number/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Dos: Adding commands to the PATH</title>
		<link>http://www.etechtips.com/2011/12/20/dos-adding-commands-to-the-path/</link>
		<comments>http://www.etechtips.com/2011/12/20/dos-adding-commands-to-the-path/#comments</comments>
		<pubDate>Tue, 20 Dec 2011 20:45:47 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[OS]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[DOS]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=589</guid>
		<description><![CDATA[When you install a new piece of software that does not add itself to the Windows PATH variable, you may find your self needing it to be run from a command prompt. You could type the full command path each time you run the executable, but it may be easier to add the directory to [...]]]></description>
			<content:encoded><![CDATA[<p>When you install a new piece of software that does not add itself to the Windows PATH variable, you may find your self<br />
needing it to be run from a command prompt. You could type the full command path each time you run the executable, but<br />
it may be easier to add the directory to the PATH variable so that it is always available.</p>
<p>To add it for the current command prompt:</p>
<pre>set PATH=%PATH%;"C:\Program Files\Sometool"</pre>
<p>This will add the variable to the current command prompt environment but will go away once you close the window and will not<br />
be available to other prompts unless you type it in again.</p>
<p>To add it to the Windows Environment, you can use the My Computer-&gt;Properties menu to select the &#8220;Advanced System Settings&#8221;<br />
in Windows 7 to then select the &#8220;Environment Variables&#8230;&#8221;. Now the choice you have is to add it to the System variables or<br />
the User variables for.</p>
<p>If you choose the System varables you will be adding it to the system as a whole and any other user who logs in will have<br />
the updated path. If you add it to the User variables, then it is only available to your user.</p>
<p>Whichever you choose, select the Path entry and click the &#8220;Edit&#8230;&#8221; button. This will pop up a dialog that will let<br />
you add to the &#8220;Variable Value&#8221; entry. Now you will need to decide whether you want your new path at the beginning, end,<br />
or somewhere in the middle. You might add it to the beginning if it is being used to override an existing command. You<br />
may add to the end if there is no conflict with other installs. And finally, you may need to choose the middle if there<br />
are some commands you need to override but others that need to be left alone.</p>
<p>Entries are separated by the semi-colon &#8220;;&#8221; character in DOS.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/12/20/dos-adding-commands-to-the-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Perl: Format date strings</title>
		<link>http://www.etechtips.com/2011/12/07/perl-format-date-strings/</link>
		<comments>http://www.etechtips.com/2011/12/07/perl-format-date-strings/#comments</comments>
		<pubDate>Wed, 07 Dec 2011 19:48:57 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=586</guid>
		<description><![CDATA[The other day I had a requirement to fill in a date value while creating an entity in ClearQuest. The field that was required was a date and was formatted as &#8220;mm/dd/yyyy hh:MM::SS AM&#124;PM&#8221;. I used the localtime function to return the date and used sprintf to format the date to the proper output. The [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I had a requirement to fill in a date value while creating an entity in ClearQuest.  The field that was required was a date and was formatted as &#8220;mm/dd/yyyy hh:MM::SS AM|PM&#8221;.  I used the localtime function to return the date and used sprintf to format the date to the proper output.<br />
The reason I used sprintf was that for hours, months and days less 10 the output was 1 digit instead of two and the input was not allowed.  The %02d states that the digits used will be a minumum of 2 in this case.</p>
<p>Here is the sample program I wrote to test the expected output:</p>
<pre>
 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;

# formatted just by concatenating output
my $datestring = $mon . "/" . $mday . "/" . $year . "  " . $hour . ":" . $min.
":" . $sec  ;

# formatted using sprintf to ensure proper digit counts are output
my $datestring2 = sprintf("%02d/%02d/%04d %d:%02d:%02d %s",$mon,$mday,1900 +$yea
r,$hour,$min,$sec, $hour >= 12? "PM" : "AM");

 print $datestring;
  print $datestring2;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/12/07/perl-format-date-strings/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>XML: Characters that require replacement</title>
		<link>http://www.etechtips.com/2011/11/20/xml-characters-that-require-replacement/</link>
		<comments>http://www.etechtips.com/2011/11/20/xml-characters-that-require-replacement/#comments</comments>
		<pubDate>Mon, 21 Nov 2011 04:11:23 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[html]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[XML]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=522</guid>
		<description><![CDATA[I was generating some html based e-mails and due to some changes I made in the text, my mail stopped being sent. I found that it was not liking some of the characters that were being placed in my generated emails. I tried some of the standard replacemnt methods, but found that the XML file [...]]]></description>
			<content:encoded><![CDATA[<p>I was generating some html based e-mails and due to some changes I made in the text, my mail stopped being sent.  I found that it was not liking some of the characters that were being placed in my generated emails.   I tried some of the standard replacemnt methods, but found that the XML file was the issue.  The Greater than(>) and less than (<) and the Amersand(&#038;) and the apostrophe(') and the quote(") all have special meaning to XML and can cause these issues. Once I replaced the following characters in my email variable, my e-mails began to flow again. </p>
<p>Here is a table of the characters and their XML representations that can be used for replacement:</p>
<table border="1" cellpadding="5" bgcolor="white">
<tr>
<td >Name</td>
<td>Character</td>
<td>XML replacement</td>
</tr>
<tr>
<td>Ampersand</td>
<td>&#038;</td>
<td>&amp;</td>
</tr>
<tr>
<td>Apostrophe</td>
<td>&apos;</td>
<td>&amp;apos;</td>
</tr>
<tr>
<td>Greater Than</td>
<td>&gt;r</td>
<td>&amp;gt;</td>
</tr>
<tr>
<td>Less than</td>
<td>&lt;</td>
<td>&amp;lt;</td>
</tr>
<tr>
<td>Quote</td>
<td>&quot;</td>
<td>&amp;quot;</td>
</tr>
</table>
<p>This is by no means the complete list of replacements.  This is only that characters that were needed by the calls to Java Mail that my program was using.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/11/20/xml-characters-that-require-replacement/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>JAVA: XMLGregorianCalendar Dates</title>
		<link>http://www.etechtips.com/2011/11/20/java-xmlgregoriancalendar-dates/</link>
		<comments>http://www.etechtips.com/2011/11/20/java-xmlgregoriancalendar-dates/#comments</comments>
		<pubDate>Sun, 20 Nov 2011 13:07:27 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=536</guid>
		<description><![CDATA[I was updating some plugins for a project and came to a query for an e-mail program I was writing, I had to send out recently introduced defects to their respective owners and insure that they would only get the defects from the a given offset. It turned out that my API had a XMLGregorianCalendar [...]]]></description>
			<content:encoded><![CDATA[<p>I was updating some plugins for a project and came to a query for an e-mail program I was writing,  I had to send out recently introduced defects to their respective owners and insure that they would only get the defects from the a given offset.  It turned out that my API had a XMLGregorianCalendar argument.  So I went out to look for a way to offset the date object so I could retrieve the correct information.  </p>
<p>I used the following to convert my date:</p>
<pre>
package com.etechtips;

import java.util.Calendar;
import java.util.GregorianCalendar;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class UpdateDate {

	public static void main(String[] args) {
		XMLGregorianCalendar xgcstart;
		GregorianCalendar gc;
		int daycount = 0;
		if (args.length != 1)
		{
			System.out.println("Need to specify offset");
			System.exit(1);
		}

		daycount = Integer.parseInt(args[0]);

		// This will get the current date based on System time of an object
		gc = new GregorianCalendar();
		System.out.println("CURRENT:" + gc.toString());

		// This will offset the date by daycount days
		gc.add(Calendar.DATE, daycount);
		System.out.println("OFFSET: "+ gc.toString());

		try
		{
			// Now the XMLGregorianCalendar object has an
                        instance that is based on the time set in the gc object
			xgcstart = DatatypeFactory.newInstance().newXMLGregorianCalendar(gc);
		}
		catch(DatatypeConfigurationException dce)
		{
			dce.printStackTrace();
			System.exit(1);
		}

		// Code omitted
	}
}
</pre>
<p>Output:</p>
<pre>
CURRENT:java.util.GregorianCalendar[time=1321793315934,areFieldsSet=true,areAllFieldsSet=true,\
lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Chicago",offset=-21600000,\
dstSavings=3600000,useDaylight=true,transitions=235,\
lastRule=java.util.SimpleTimeZone[id=America/Chicago,offset=-21600000,dstSavings=3600000,\
useDaylight=true,startYear=0,startMode=3,startMonth=2,startDay=8,startDayOfWeek=1,\
startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,endDayOfWeek=1,endTime=7200000,\
endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2011,MONTH=10,\
WEEK_OF_YEAR=48,WEEK_OF_MONTH=4,<strong>DAY_OF_MONTH=20</strong>,DAY_OF_YEAR=324,DAY_OF_WEEK=1,DAY_OF_WEEK_IN_MONTH=3,\
AM_PM=0,HOUR=6,HOUR_OF_DAY=6,MINUTE=48,SECOND=35,MILLISECOND=934,ZONE_OFFSET=-21600000,\
DST_OFFSET=0]
OFFSET: java.util.GregorianCalendar[time=1321706915934,areFieldsSet=true,areAllFieldsSet=true,\
lenient=true,zone=sun.util.calendar.ZoneInfo[id="America/Chicago",offset=-21600000,\
dstSavings=3600000,useDaylight=true,transitions=235,lastRule=java.util.SimpleTimeZone[id=America/Chicago,\
offset=-21600000,dstSavings=3600000,useDaylight=true,startYear=0,startMode=3,startMonth=2,\
startDay=8,startDayOfWeek=1,startTime=7200000,startTimeMode=0,endMode=3,endMonth=10,endDay=1,\
endDayOfWeek=1,endTime=7200000,endTimeMode=0]],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,\
YEAR=2011,MONTH=10,WEEK_OF_YEAR=47,WEEK_OF_MONTH=3,<strong>DAY_OF_MONTH=19</strong>,DAY_OF_YEAR=323,\
DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=3,AM_PM=0,HOUR=6,HOUR_OF_DAY=6,MINUTE=48,SECOND=35,\
MILLISECOND=934,ZONE_OFFSET=-21600000,DST_OFFSET=0]
</pre>
<p>The printouts above show the current date and the new date based on the offset.  I made the day of the month bold in the printouts to show what the offset has updated the date.  You could put a much larger offset than 1 and Calendar object will take care of updating the day of week, week of year and more. You will not need to deal with checking for leap year or dealing with updating all the month and years, this is all taken care of for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/11/20/java-xmlgregoriancalendar-dates/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>DOS: Check for empty environment variable</title>
		<link>http://www.etechtips.com/2011/11/16/dos-check-for-empty-environment-variable/</link>
		<comments>http://www.etechtips.com/2011/11/16/dos-check-for-empty-environment-variable/#comments</comments>
		<pubDate>Wed, 16 Nov 2011 20:52:57 +0000</pubDate>
		<dc:creator>ecdown</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[DOS]]></category>
		<category><![CDATA[scripting]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=527</guid>
		<description><![CDATA[I was writing a batch file the other day and needed to change the argumets to a command based on if the user had specified his password on the command line. SET PASS=somepassword : or :SET PASS= if x%PASS%= X ( SET PASSARG=--password somepassword ) else ( SET PASSARG= ) commandtorun %PASSARG% Now if the [...]]]></description>
			<content:encoded><![CDATA[<p>I was writing a batch file the other day and needed to change the argumets to a command based on if the user had specified his password on the command line.</p>
<pre>
SET PASS=somepassword
: or
:SET PASS=
if x%PASS%= X (
  SET PASSARG=--password somepassword
) else
(
  SET PASSARG=
)

commandtorun %PASSARG%
</pre>
<p>Now if the user comments out his password, the script will make the PASSARG environment variable be empty or if they set a password the passarg variable will be filled in.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/11/16/dos-check-for-empty-environment-variable/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Java: Command line argument processing</title>
		<link>http://www.etechtips.com/2011/11/06/java-command-line-argument-processing/</link>
		<comments>http://www.etechtips.com/2011/11/06/java-command-line-argument-processing/#comments</comments>
		<pubDate>Mon, 07 Nov 2011 04:44:15 +0000</pubDate>
		<dc:creator>techtipse</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Shell]]></category>
		<category><![CDATA[Utilities]]></category>
		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.etechtips.com/?p=71</guid>
		<description><![CDATA[In each language that I have learned I have found it useful to know how to process command line arguments and here is a simple framework that I use for Java. I usually wrap the java command line in a bat or shell file to make it easier to run so that the user does [...]]]></description>
			<content:encoded><![CDATA[<p>In each language that I have learned I have found it useful to know how to process command line arguments and here is a simple framework that I use for Java.  I usually wrap the java command line in a bat or shell file to make it easier to run so that the user does not have to worry about classpath or path issues.</p>
<p>The following is the basic code to handle the command line arguments.</p>
<pre>
class CmdArgs
{

  public static void main(String[] args)
  {
      int argsize = args.length;
      String curarg;

      if (argsize > 0 )
      {

      }

      for(int i = 0; i < argsize; i++)
      {
          if (args[i].equals("--host")
          {
             args++;
             host = args[i];
           }
          else if (args[i].equals("--debug")
          {
               debug = 1;
          }
          else
          {
              System.out.println("Unknown option: " + args[i]);
              System.exit(1);
          }
       }

   }
}
</pre>
<p>The bat file for Dos/Windows might look like this:</p>
<pre>
@echo off

java -cp c:\javabin;somejar.jar  com.etechtips.CmdArgs %*
</pre>
<p>The shell based file might look like:</p>
<pre>

java -cp /home/ecdown/javabin:somejar.jar com.etechtips.CmdArgs $*
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.etechtips.com/2011/11/06/java-command-line-argument-processing/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

