954,504 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

passing parameters to .exe file using C++

Hi,

I'm trying to pass parameters to an exe file using C++...i tried the following code:

system("FileName.exe");

but this command line just fire the .exe file without passing any arguments...

Thanks,

Mostafa Fouly

Fouly
Light Poster
30 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 

I've never done this, but it doesn't look you passed any arguments? What about

system("FileName.exe arg1 arg2");
daviddoria
Posting Virtuoso
1,996 posts since Feb 2008
Reputation Points: 437
Solved Threads: 204
 

Hi,

I'm trying to pass parameters to an exe file using C++...i tried the following code:

system("FileName.exe");

but this command line just fire the .exe file without passing any arguments...

Thanks,

Mostafa Fouly


In order to pass arguments you have to pass arguments. All you did was execute the program.

WaltP
Posting Sage w/ dash of thyme
Moderator
10,506 posts since May 2006
Reputation Points: 3,348
Solved Threads: 944
 

yes i know that in this example i just passed fired the .exe file and that's am asking about how to pass arguments to an exe file???

Fouly
Light Poster
30 posts since Oct 2007
Reputation Points: 10
Solved Threads: 0
 
I've never done this, but it doesn't look you passed any arguments


You are right. he has just called the program without any command line argument.
Also, you answered it rightly to him.
As a matter of explanation: the system() function takes a Cstring and pass it to the command prompt( or terminal or shell for Linux user) and then returns a value which is platform dependent.
So, while using system(), assume as if you were typing everything at the command prompt.
So, the correct thing as daviddoria said, will be: system("FileName.exe arg1 arg2");
Also this is even good:

std::string s1;
getline(std::cin,s1);//take command from user
system(s1.c_str());//pass it to the shell
siddhant3s
Practically a Posting Shark
816 posts since Oct 2007
Reputation Points: 1,486
Solved Threads: 140
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You