Forums

Is there any way to modify the commandLineArgs array?

General discussion about Cobra. Releases and general news will also be posted here.
Feel free to ask questions or just say "Hello".

Is there any way to modify the commandLineArgs array?

Postby Gameday » Sun May 09, 2010 9:41 am

CobraCore.commandLineArgs is read-only.
Is there any way of modifying the list of arguments passed to the program?
Gameday
 
Posts: 27

Re: Is there any way to modify the commandLineArgs array?

Postby Charles » Sun May 09, 2010 11:25 am

The list you get back can be modified, but if you invoke the method again from somewhere else, you get a new list:
get commandLineArgs as List<of String>
return List<of String>(Environment.getCommandLineArgs)

I just always assign it to a local anyway and then pass it around if I need to. Something like:
class Program

def main
args = CobraCore.commandLineArgs
for arg in args, print arg
Foo().bar(args)

class Foo

def bar(args as IList<of String>)
pass

This also means that Foo().bar() can be reused in other ways because it takes an argument instead of using a global source. Also you can do this if you want to skip the program name:
args = CobraCore.commandLineArgs[1:]

HTH
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Is there any way to modify the commandLineArgs array?

Postby Gameday » Sun May 09, 2010 11:30 am

Oh, so there is no way to modify the original argument list? In Ruby I could do ARGV.clear and it would empty the command line arguments.
I realize this may not be the way to go, but I just wanted to know if it was possible :)
Gameday
 
Posts: 27

Re: Is there any way to modify the commandLineArgs array?

Postby Charles » Sun May 09, 2010 5:36 pm

I don't think there is. The args originally come from the "Environment" class whose members are listed here:
http://msdn.microsoft.com/en-us/library/system.environment_members.aspx

But I don't see anything to clear them.
Charles
 
Posts: 2515
Location: Los Angeles, CA

Re: Is there any way to modify the commandLineArgs array?

Postby CodexArcanum » Mon May 10, 2010 9:05 pm

Yeah, I don't think in .NET there's any straight forward method of going about that. Now I'm curious though, why would you want to clear or modify the command line arguments?
CodexArcanum
 
Posts: 21


Return to Discussion

Who is online

Users browsing this forum: No registered users and 54 guests