Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9079867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T19:56:13+00:00 2026-06-16T19:56:13+00:00

I have been trying to put my head around this. There are no errors

  • 0

I have been trying to put my head around this. There are no errors but I am not seeing the desired answer:

public class Clopts {
    private static Options options = null; 

    private static final String InputDir = "i";
    private static final String OutputDir = "o";
    private String input;
    private CommandLine cmd = null; 

    static{
            options = new Options();
            options.addOption(InputDir, false, "Input Directory");
            options.addOption(OutputDir, false, "Output Directory. " + OutputDir );
        }

    public static void main(String[] args) {
        Clopts cliProg = new Clopts();
        cliProg.loadArgs(args);
    }

    private void loadArgs(String[] args){
        CommandLineParser parser = new PosixParser();
        try {
            cmd = parser.parse(options, args);
        } catch (ParseException e) {
            System.err.println("Error parsing arguments");
            e.printStackTrace();
            System.exit(1);
        }

        if (cmd.hasOption(InputDir)){
            input = cmd.getOptionValue(InputDir);
            System.out.println(input); // This is always null :(
        }
    }
}

While I am passing the argument -i foo -o bar
But I am not seeing the foo or bar every time i see is null.

Also I want to println in the main module. How do i get the options from command line and then print out what the options are.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T19:56:15+00:00Added an answer on June 16, 2026 at 7:56 pm

    When you define your options with:

    options.addOption(InputDir, false, "Input Directory");
    options.addOption(OutputDir, false, "Output Directory. " + OutputDir );
    

    The false means they don’t take arguments. If you want an option value you must specify true here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

from morning I have been trying but at last I have to put this
I have been trying to fix this issue for the past 2-3 hours but
So I have been trying to put a div side by side here but
I've been trying to wrap my head around this particular issue for two days
Been trying to get my head around while loops for the last few days
I have been trying to put together something that allows me to extract points
Okay, so I've been trying to wrap my head around queue -> dead-letter queue
All this weekend I have been trying to setup a Rails 3.0.4 app in
I've been trying to get my head around the Android orientation sensors for a
I've been trying to add JavaScript to my HTML/CSS, but been running around in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.