473,765 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Parsing Command-Line Arguments with InstallContext

I'm using the InstallContext class to parse the command-line arguments of a console application. The arguments are in the form of "-file=myFile.txt -flag", and the InstallContext object gives me what I need through the Parameters and IsParameterTrue properties.

However, I can't find any documentation or code samples that confirm that this is an acceptable use of the InstallContext class. I understand the need to use Regex or some other means to parse more complex command-line arguments, but I'm surprised to find no mention of this simple parsing alternative. Is there anything wrong with using InstallContext for this purpose

using System;
using System.Configur ation.Install;
using System.Collecti ons.Specialized ;

class MyClass
{
public static void Main(string[] args)
{
InstallContext context = new InstallContext( null, args);
StringDictionar y parameters = context.Paramet ers;

string file = parameters["file"];
bool flag = context.IsParam eterTrue("flag" );

Console.WriteLi ne("file = {0}", file);
Console.WriteLi ne("flag = {0}", flag);
}
}
Nov 16 '05 #1
1 9647
"=?Utf-8?B?bXJpZWRlbA= =?=" <an*******@disc ussions.microso ft.com>
wrote in news:D9******** *************** ***********@mic rosoft.com:
I'm using the InstallContext class to parse the command-line
arguments of a console application. The arguments are in the
form of "-file=myFile.txt -flag", and the InstallContext object
gives me what I need through the Parameters and IsParameterTrue
properties.

However, I can't find any documentation or code samples that
confirm that this is an acceptable use of the InstallContext
class. I understand the need to use Regex or some other means to
parse more complex command-line arguments, but I'm surprised to
find no mention of this simple parsing alternative. Is there
anything wrong with using InstallContext for this purpose?


I looked at the underlying source code for InstallContext with
Reflector (http://www.aisto.com/roeder/DotNet/). As far as I can
see, InstallContext doesn't produce any side effects, so it looks
safe to use.

Thanks for bringing this class to light. With over 5000 classes in
the framework, it's too easy to overlook a gem like this.

--
Hope this helps.

Chris.
-------------
C.R. Timmons Consulting, Inc.
http://www.crtimmonsinc.com/
Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2525
by: InsaneScouter | last post by:
I am running a shell command via a php started ssh connection to a mail server. I need to grab the data the shell command displays and then load them into variables or an array ... Can anyone give me ideas on how to do this ... Note: I posted this on alt.php.sql ... so this is a cross post... Scott www.insaneweb.net
4
10938
by: Uwe Ziegenhagen | last post by:
Hello, my fellows and me implement a c++ tool that is able to divide blank/tab separated files into <number>, <text>, <c-singlelinecomment> and <multilinecomment>. So far it's not working bad, we have just one problem if I call the a.exe that gcc compiles with the following textfile (./a.exe < test.txt) he does not match the multiline comments correctly. *test.txt contains:
9
8456
by: Rob | last post by:
I am trying to write a program with VC++ 6.0 to read a txt file which looks like this: Network Destination Netmask Gateway Interface Metric 0.0.0.0 0.0.0.0 10.155.12.1 10.155.12.188 1 10.155.12.0 255.255.255.0 10.155.12.188 10.155.12.188 1 10.155.12.188 255.255.255.255 127.0.0.1 127.0.0.1
6
2409
by: John Paulsson | last post by:
Is there a C# pattern or perhaps a .NET framework way of parsing a command lines, supporting quoted filepaths etc? (I'm not talking about the current applications command arguments. I've got command strings that I need to parse into an array)
0
1937
by: Seth | last post by:
First off, my apologies if this is in the wrong newsgroup, but I hope I'm close enough. I'm trying to do some parsing of a CSV file using OleDbConnection, but for some reason, when I populate my DataSet, it is trimming the trailing spaces. Anybody know why? Here is my code: System.Data.OleDb.OleDbConnection connection = null;
3
1608
by: David Svoboda | last post by:
I have a server program that takes commands and acts on them. The server program can also take these commands from an input file or standard input (mainly for testing purposes). As such, I often have files full of input commands to feed to the server. Right now the commands that the server takes are well-defined, but not in XML. Since the commands are not self-delimiting, I have to prepend each command with a 'length' number indicating...
2
2107
by: JaythePCguy | last post by:
Hi, I am trying to write a text parser to group all nonprintable and control characters, spaces and space delimited words in different groups using Regex class. Using a parsing of (?<Commands>)|(?<Spaces>)|(?<Text>+) on my sample text of \tOne\ncar red \fcar\a blue car\r\n \r\n does not work as indetended. Specially, the spaces are grouped as commands and the Text grouping ends up grouping words delimited by spaces. Here is the sample...
4
1910
by: Jim Langston | last post by:
In my program I am accepting messages over the network and parsing them. I find that the function that does this has gotten quite big, and so want to break the if else code into functions. I started thinking of how to do this, but came up with a number of ways and don't know what would be best, and fit into the C++ idoism. This is what I have now: if ( ThisPlayer.Character.GMLevel == 100 && ( StrMessage == "/debugserver" ||...
2
1875
by: Andy | last post by:
Hi guys, I'm writing a program with a feature of accepting user input as command text and parsing it to correct function calls...example: "5 minutes later"/"5 min later"/"5 minute later"/"after 5 minutes"... are being parsed as the same rule so the system will call a later function with minutes=5 as parameter. Of course there are many other possiblilities, "seconds"/"days", and
8
1738
by: lawrence k | last post by:
I have to parse some FTP logs, which are full of several thousand lines like this: Thu Sep 4 11:39:04 2008 FTP command: Client "74.231.146.2", "TYPE A" Thu Sep 4 11:39:04 2008 FTP response: Client "74.231.146.2", "200 Switching to ASCII mode." Thu Sep 4 11:39:07 2008 FTP command: Client "74.231.146.2", "PWD" Thu Sep 4 11:39:07 2008 FTP response: Client
0
9568
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9398
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10160
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
7378
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5275
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5421
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3531
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2805
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.