4 Replies - 8343 Views - Last Post: 31 May 2011 - 03:06 PM

#1 blank_program  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 282
  • Joined: 22-July 09

Console application commands: best practices?

Posted 19 May 2011 - 09:02 AM

I am going to be working on a command line program so I do not need to distract myself with GUI code and tryign to decide on how I want it to look but then I hit a wall because I started thinking: whats the best way to handle the commands.

Should I just take them and split the string? If so how do I handle command arguments that would be wrapped in quotes if they contain spaces?

Do I reuse the same list object for holding all parts of the command? Or maybe a whole command class, but then I have to limit the arguements somehow?

Anyone have good suggestions for me? I guess I could write a GUI but I tend to be really picky with that and waste more time on the GUI then I do the actual code and then it gets all tangled up. Plus if I did a GUI it would be WPF and that has its own learnign curve I am still fighting with.

Is This A Good Question/Topic? 0
  • +

Replies To: Console application commands: best practices?

#2 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 4437
  • View blog
  • Posts: 7,719
  • Joined: 08-June 10

Re: Console application commands: best practices?

Posted 19 May 2011 - 08:05 PM

Well, it depends. If you're talking about standard command line arguments, they 're stored in the args parameter of the Main method. So you can just get each from there. Those are the arguments that you pass when you start the program.
Was This Post Helpful? 0
  • +
  • -

#3 MentalFloss  Icon User is offline

  • "ADDICTED"[2:5]
  • member icon

Reputation: 526
  • View blog
  • Posts: 1,397
  • Joined: 02-September 09

Re: Console application commands: best practices?

Posted 21 May 2011 - 02:46 AM

If it's pretty involved, you might consider the getopt lib.
Was This Post Helpful? 0
  • +
  • -

#4 blank_program  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 11
  • View blog
  • Posts: 282
  • Joined: 22-July 09

Re: Console application commands: best practices?

Posted 30 May 2011 - 08:48 AM

View PostCurtis Rutland, on 19 May 2011 - 11:05 PM, said:

Well, it depends. If you're talking about standard command line arguments, they 're stored in the args parameter of the Main method. So you can just get each from there. Those are the arguments that you pass when you start the program.

I don't mean arguements to start the program I am talking about have the user type somethign like this into my program:
start "C:\Program Files\Mozilla\Firefox.exe"

Or something similar. If I split it on the space then it breaks the filepath up, so I am wondering how to handle it.
Was This Post Helpful? 0
  • +
  • -

#5 MATTtheSEAHAWK  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 137
  • View blog
  • Posts: 782
  • Joined: 11-September 10

Re: Console application commands: best practices?

Posted 31 May 2011 - 03:06 PM

Well you could let the user give commands/parameters following a special character or a few like: -XF:Command Here. Then you could have spaces in the argument and just split where you need to. Or you could retrieve by index and then read until you get to another command.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1