OrMoush
OrMoush

Reputation: 205

Print argument from Console

i'm tring to run argument from ubuntu console.

./myTool -h

and all i get is only the print of "1".

someone can help please ?

thanks !

public static void main(String[] argv) throws Exception
{

    System.out.println("1");
    for(int i=0;i<argv.length;i++)
    {
        if (argv.equals("-h"))
        {
            System.out.println("-ip   target ip address\n");
            System.out.println("-t    time interval between each scan in milliseconds\n");
            System.out.println("-p    protocol type [UDP/TCP/ICMP]\n");
            System.out.println("-type scan type [full,stealth,fin,ack]\n");
            System.out.println("-b    bannerGrabber status\n");

        }

}

Upvotes: 2

Views: 137

Answers (4)

Drogba
Drogba

Reputation: 4346

You miss the array index in the if condition:

argv[i].equals("-h")

Upvotes: 2

npinti
npinti

Reputation: 52185

argv is an entire array. What you are trying to match, is the entire content of the array with the string -h. Try doing this:

public static void main(String[] argv) throws Exception
{

    System.out.println("1");
    for(int i=0;i<argv.length;i++)
    {
        if (argv[i].equals("-h"))
        {
            System.out.println("-ip   target ip address\n");
            System.out.println("-t    time interval between each scan in milliseconds\n");
            System.out.println("-p    protocol type [UDP/TCP/ICMP]\n");
            System.out.println("-type scan type [full,stealth,fin,ack]\n");
            System.out.println("-b    bannerGrabber status\n");

        }
     }
}

Side Note: This previous SO post might also be worth going through.

Upvotes: 2

BobTheBuilder
BobTheBuilder

Reputation: 19284

You try to compare String[] with String.

Try instead:

    if (argv[i].equals("-h"))

Upvotes: 0

Klas Lindb&#228;ck
Klas Lindb&#228;ck

Reputation: 33273

You are comparing an array with a string. Change it to:

   if (argv[i].equals("-h"))

Upvotes: 0

Related Questions