Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C++ and Visual C++ > C++ Programming
|
C++ Programming General discussions for the C++ language. For questions specific to Microsoft's Visual C++ variant, see the Visual C++ forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C++ Programming section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old January 12th, 2007, 09:17 PM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to iulian
Default take arguments when running program in console

Hi,
I am a newbie to C++. I'm almost sure that there is the possibility to take parameters when running program in console.

Ex.:
program.exe /a etc ...
How can I get those parameters and values in program?

Thanks in advance!

Reply With Quote
  #2 (permalink)  
Old January 14th, 2007, 07:33 AM
Authorized User
 
Join Date: Oct 2006
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hi,

  i think you should locate the file you saved.....
im not sure about your problem what do you want to intend for...but i guess your problem if im not mistaken is you want to run your program in console..
what if you download the windows application of c++ like (dev-c++)....

______________________________________
.::If you quit you loss, If you survive you win::.

.::JHANNY::.

Reply With Quote
  #3 (permalink)  
Old January 14th, 2007, 06:20 PM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to iulian
Default

Nice reply, but it's not what I want.
I give you an example: i've created a program in c++ ( :) so I know about Dev-C++, Visual C++) and now I want to run the program from phph through system() or exec().
exec("program.exe /arguments_here")
Question based on the above example: how can I get the /arguments_here list?

Reply With Quote
  #4 (permalink)  
Old January 16th, 2007, 08:20 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 103
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Geo121
Default

if I am understanding your question correctly than you want it to where in the command prompt you can type :

program.exe /a 2 2

where program.exe uses a as a parameter to add the two numbers

this may not be what your program does but I'm using this as an example. If this is what you would like to do then you are in luck because it is absolutely EASY!!!!

~ Geo

~ Don't take life too seriously, you'll never get out alive!
Reply With Quote
  #5 (permalink)  
Old January 16th, 2007, 08:27 AM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to iulian
Default

This is exactly what I intend to do. But I can't figure out. Maybe using some parameters for function main()?
Reply With Quote
  #6 (permalink)  
Old January 16th, 2007, 08:33 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 103
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Geo121
Default

Exactly!!!!

In order to do this you must create parameters for the main function

EX:

int main(int argc, char *argv[]) {
     char x = *argv[1];
     int a, b;
     a = atoi(argv[2]);
     b = atoi(argv[3]);
}

now ignore the atoi function if you don't know what it is. (Parsing function)

What the above shows is parameters that are used for the example I posted above

this can apply to anything.

The argv[] applies to what you type after your program in the console window

so if its the first parameter it will be argv[1]

now this may be slightly confusing if you don't understand pointers so if you have any more questions about it just ask.

~ Geo

~ Don't take life too seriously, you'll never get out alive!
Reply With Quote
  #7 (permalink)  
Old January 16th, 2007, 08:58 AM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to iulian
Default

This is exactly what I wanted to do. Thanks!

P.S. I agree with you about the last line in the post (quote :) )
Reply With Quote
  #8 (permalink)  
Old January 16th, 2007, 09:01 AM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 103
Thanks: 0
Thanked 1 Time in 1 Post
Send a message via AIM to Geo121
Default

No problem, is it working?

If you have any issues or additional questions just ask.

And this is my favorite quote because if you don't take time to take a break you'll end up missing your chance

~ Geo

~ Don't take life too seriously, you'll never get out alive!
Reply With Quote
  #9 (permalink)  
Old January 16th, 2007, 09:17 AM
Registered User
 
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to iulian
Default

I did not test it. I'm at work right now and I have something else to do. I got the ideea. When I first see your post some things were unclear in my head: what is argc. I hit search on google and I found.
Reply With Quote





Similar Threads
Thread Thread Starter Forum Replies Last Post
Finding commandline arguments of a running process EddyT C# 4 July 1st, 2007 10:07 AM
Exception in running a program furqanms Java Basics 2 June 21st, 2006 10:39 PM
running another .exe from my program salhabb C++ Programming 1 January 18th, 2006 06:21 AM
Pass arguments to dos program gregquinn Beginning VB 6 1 December 10th, 2003 05:38 AM
Program arguments bramtram VB How-To 1 August 14th, 2003 03:18 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.