Command Line Arguments
Page 1 of 1
Is this help ful?
Command Line Arguments
Dear students following i have told some information about Command Line Argument which you must know. Command Line Arguments are used to Associate file types to some specific executable. For example when ever you double clicked on a file with extension .txt, that file automatically opened in Notepad. Have you ever noticed why it is like this..??
This is why because windows has made association of .txt with Notepad. Same .mp3 files are associated with Windows Media Player, that is why when ever you double clicked a .mp3 file it automatically plays in Windows Media Player.
Whats going on behind the scenes?
When you double clicked a file Windows searches the associated Program in its registry information and executes the program by passing a Command Line Argument to that particular application.
What is that Command Line Argument?
The file name which you have double clicked is the Argument passed to that application.
Associating File Types
You have written few programs using Command Line Arguments, but in those programs you need to give the parameter by typing yourself. Now we will associate file types with our program. In this case when ever we double click a File our Program will open it automatically.
There are two ways to associate a file type with you program.
One is to write directly to registry and other is very simple. Open With command.
First compile your program.
For example you have written a program which takes a text file as input and displays it. So we will associate .txt files with out program.
Write click on any .txt file and the choose Open With.... A dialog box will appear asking you to choose the application. Here you have to browse for your application's executable file. Select it and click on OK. Now double click on any .txt file. Windows will automatically run your program and view the file.
This is why because windows has made association of .txt with Notepad. Same .mp3 files are associated with Windows Media Player, that is why when ever you double clicked a .mp3 file it automatically plays in Windows Media Player.
Whats going on behind the scenes?
When you double clicked a file Windows searches the associated Program in its registry information and executes the program by passing a Command Line Argument to that particular application.
What is that Command Line Argument?
The file name which you have double clicked is the Argument passed to that application.
Associating File Types
You have written few programs using Command Line Arguments, but in those programs you need to give the parameter by typing yourself. Now we will associate file types with our program. In this case when ever we double click a File our Program will open it automatically.
There are two ways to associate a file type with you program.
One is to write directly to registry and other is very simple. Open With command.
First compile your program.
For example you have written a program which takes a text file as input and displays it. So we will associate .txt files with out program.
Write click on any .txt file and the choose Open With.... A dialog box will appear asking you to choose the application. Here you have to browse for your application's executable file. Select it and click on OK. Now double click on any .txt file. Windows will automatically run your program and view the file.
Page 1 of 1
Permissions in this forum:
You cannot reply to topics in this forum