473,671 Members | 2,422 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Command Prompt input

114 New Member
How do u get input from the command prompt as a program argument? like there is the javac program that accepts arguments to work.
Sep 24 '07 #1
5 1990
Ganon11
3,652 Recognized Expert Specialist
I believe you use

Expand|Select|Wrap|Line Numbers
  1. int main(int argc, char *argv[])
The command line arguments are stored in argv. So if you typed:

Expand|Select|Wrap|Line Numbers
  1. myProg.exe My name is Ganon.
then argv[1] contains "My\0", argv[2] contains "name\0", and so on.

argc is the number of arguments passed; in the previous example, argc holds 4.
Sep 24 '07 #2
Banfa
9,065 Recognized Expert Moderator Expert
Expand|Select|Wrap|Line Numbers
  1. myProg.exe My name is Ganon.
then argv[1] contains "My\0", argv[2] contains "name\0", and so on.

argc is the number of arguments passed; in the previous example, argc holds 4.
Remember that argv[0] contains the program name "myProg.exe " so in your example argc actual holds 5.
Sep 24 '07 #3
Firecore
114 New Member
Um.
I didnt really get it.
can u plz sho me an example?
Im not that smart.
Sep 24 '07 #4
Banfa
9,065 Recognized Expert Moderator Expert
Compile and run this, put something(anyth ing) on the command line
Expand|Select|Wrap|Line Numbers
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3.  
  4.  
  5. int main(int argc, char **argv)
  6. {
  7.     int ix;
  8.  
  9.     for(ix=0; ix<argc; ix++)
  10.     {
  11.         printf("%3d: %s\n", ix, argv[ix]);
  12.     }
  13.  
  14.     return 0;
  15. }
  16.  
Sep 24 '07 #5
forse
7 New Member
Check out Using command-line arguments in C++
Sep 24 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1853
by: Kim Ipsen | last post by:
Hi. I don't know if this possible but how would you do it if you wanted to send commands til the comman prompt (and preferrably also receive the output from the command prompt - though not necessary!) ? I need to send a number of commands to the command prompt and I can't really use the System.Diagnostics.Process class.
7
6610
by: David A. Osborn | last post by:
I am current writing a console program that takes two file paths as command line input. I get the command line input using the following code: parameter = Split(Command()) input = parameter(0) output = parameter(1) Unforunately this method does not handle embedded spaces in the file paths, for example C:\Documents and Settings\Administrator. Is there a simple way to handle this? From my command prompt experience I know that paths...
17
7914
by: comp.lang.tcl | last post by:
The TCL command I am using will do a command-line action on a PHP script: set cannotRunPHP I have to do it this way as both the TCL script and the PHP script run as CLI. However, "info.php" requires user input to run; this causes the TCL script calling the PHP script to hose up and die. Is there a way I can do this so that the TCL script can call the PHP
34
6849
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: 1) get whole string of input line 2) preset table of strings matching <command> 3) preset table of function calls
11
8781
by: gert365 | last post by:
I'm working on a scirpt to be used on a windows machine and I need to automate a user's input on the command prompt. For example I'm using os.system('mycommand') to excute the commands I want. However some of these command will prompt for a confirmation of yes or no from user. Is there anything in python that will allow my script to automate these input Another example is let say if i type "format c:\" on the command prompt it will...
3
2267
by: Steven | last post by:
I am using VC++ 6.0 to build a windows based application, however, my application allows user to input command arguments in the dos prompt windows. I want to have a warning message for user if they have input the wrong arguments. How can I write text to the dos prompt windows if user input the wrong arguments? Thanks in advance. Steven.
6
5613
by: evantri | last post by:
I am developing a program that prompt the input from the command line argument. For example, this is the lists of command line arguments that I want to include: -fish -cat -dog -animal All command line arguments can be in any order, BUT -animal must be in the last command line argument otherwise error message displayed Let's say this input at the command line (using cc compiler)
1
2176
by: viswasai2k | last post by:
I have created a example.exe. And i am running this example.exe in the command prompt. when the example.exe is running i have to give a string input and coming next line another user input to command prompt. As the process waits for the user input. for every input it should be next line means the enter button should be pressed.
3
5105
by: kimiraikkonen | last post by:
Hi experts, I just want to ask a simple procedure of my simple form. My form has a input textbox and a button. I want this if you can help me: Application user types a command prompt command like "dir" into "textbox", then after clicking "button", command prompt(cmd) should run with the prompt that user has written already into "textbox" .
2
4279
by: megatrious | last post by:
I have a windows command line tool that accepts certain input parameters and runs a process and displays a report. I want to develop a Java GUI for that tool. Input parameters need to be given in the GUI and the GUI should start the command in cmd prompt and captures the cmd prompt output and should display the output in the GUI window. I want to know how to make the event listener to start the command by passing the parameters once a...
0
8483
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
8401
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
8926
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
8603
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8673
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7444
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5703
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
4416
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1815
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.