Welcome! Log In Create A New Profile

Advanced

CommandLine Arguments

Posted by African Boy 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
CommandLine Arguments
January 23, 2012 07:08AM
Anyone with a simple elegant explanation of what commandlines are and how are used?
Thanks
Re: CommandLine Arguments
January 24, 2012 12:08PM
Command line arguments, its like how you used to code cin >> ... for input. Command-line arguments, is almost similar, to my understanding.

command-line arguments

Ronica
Re: CommandLine Arguments
January 26, 2012 11:27AM
Bascially, without having read the link in the above post, here's a very simple explanation:

In Windows, the graphical interface allows for applications, etc to be represented by icons or in menus, which can be selected using a pointing device.
When using a command line interface, the name of the command is typed out to launch it.

Now thats a very basic explanation, and one from some of the previous year modules explaining what a CLI and GUI are.

To follow on from the above, when launching an application, certain additional parameters can be "passed" or provided to the application; this may be to run the application in a slightly different way, or to provide certain filtering techniques, or... etc.
In a CLI, these extra parameters would typically be typed after the name of the application to be run.
In a GUI, these would need to be provided in some or other way, such as editing the command to be run in the applicable icon window. for example, in Windows, this may be done by right clicking the icon, slecting Properties, and then putting the extra parameters into the 'Target' box after the command name (which resembles the CLI version of launching the application).

These extra parameters are the arguements to the application.

If you are writing an application, these arguements need to be handled by your application in order to be used. Typically, this is why there are parameters to the main() function - typically the 'int' parameter specifies the number of arguements that were provided, and then the array parameter contains the list of actual arguements that were provided, the first typically being the name of the command that was launched. Its up to your application to then provided any necessary code handling to handle any specific arguement.

For example (in Windows):
Open the command prompt (cmd).
In the command prompt window, type 'dir' (without the quote marks).
This lists the files in the current directory.
Now type in the command (again without the quote marks) 'dir /?'
This shows the parameters/arguements that can be used with the dir command.
The '/?' of the second command is an arguement to the dir application. The dir application execute, and looks if any arguements are provided, and thereafter handles known ones appropriately. In this case, the dir command detects that the /? argument was used, and so it handles it appropriately.
If the arguement '/!@' was used, it would have no effect on the dir command, since the command does not handle /!@ arguements. In this case, the dir command ignores the arguement and continues as normal.
Re: CommandLine Arguments
February 19, 2012 07:36PM
Yeah, I agree with what wishblade said.

They are often called "parameters" or "flags" in programs. Just like when you pass one or more parameters into a function,
you are now passing one or more "parameters" into the main() function of your program. (From the Command Line)


Like if you've ever used telnet. What I would type at command prompt is " telnet ServerName PortNumber "

Here, "ServerName" and "PortNumber" are my command line arguments or parameters.

So if I wanted to access my mail server on Mweb on port 25 I'd go " telnet mail.mweb.co.za 25 "

and there I have just passed two parameters to the main() function of the executable file "telnet"
Sorry, only registered users may post in this forum.

Click here to login