Page 1 of 1

Is there any way to modify the commandLineArgs array?

PostPosted: Sun May 09, 2010 9:41 am
by Gameday
CobraCore.commandLineArgs is read-only.
Is there any way of modifying the list of arguments passed to the program?

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

PostPosted: Sun May 09, 2010 11:25 am
by Charles
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

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

PostPosted: Sun May 09, 2010 11:30 am
by Gameday
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 :)

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

PostPosted: Sun May 09, 2010 5:36 pm
by Charles
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.

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

PostPosted: Mon May 10, 2010 9:05 pm
by CodexArcanum
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?