How to operate an '.exe' using C++

I need to use a '.exe' file to operate through the C++ program. I am using system(). for the operation of the '.exe' file, I need to put some command to the '.exe' file after opening. I dnt understand how to put the command.
closed account (j2NvC542)
Perhaps you can pass a parameter to the exe? What exe is it?
There are much better ways than system. What operating system are you using?
1
2
3
4
5
6
#include "windows.h"

int main()
{
    system("start firefox.exe -safe-mode");
}
system always work but too dangerous.
and also when you use system your application stay ready until that application end. which is not good.
sometimes system goes buggy, and result in too many errors! I've never figured out how to resolve them.

try using something other than system
I am using windows!! I have a program (model) that is written in FORTRAN. I need to use the same program (exe) with some parameters changed repeatedly using the C++.
you have source for FORTRAN ?
if not you cant change any parameters.
if so there might be some ways,
If you have fortran source code you may be able to convert it to C code using f2c.

If you wish to stick to creating a subprocess - take a look at CreateProcess function from Windows SDK ( http://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx ), or boost process ( http://www.highscore.de/boost/process/ not yet official part of boost) or use QProcess (a part of Qt library - see http://qt.nokia.com/ )
Sorry!! I could not explain the problem properly. I am using the exe file of the fortran code via the command prompt. while using the exe file i need to write the following in the command prompt...

daycent -n example -s example1

example is a input file to the exe. and example1 is the output file. I want to do this step only using the C++
just use this command:

system("daycent -n -example -s example1");

you must put daycent in same folder as your program

just dont forget that the input of system is not string, is a char*.
1
2
3
4
5
6
#include "windows.h"

int main()
{
    system("start daycent.exe -n example.txt -s example1.txt");
}
Thank you
Use CreateProcess() as you have been told, system() has few major issues you will encounter sooner or later, like using .exe name which contains spaces in it :)
I am using the following command. But it is unable to read the exe. Can anybody explain where is the problem??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include<iostream>
#include<fstream>
#include<Windows.h>


using namespace std;
void main ()
{


system("start dailydaycent.exe dailydaycent -s example -n example");


system("pause");
}
Is the file dailydaycent.exe in the same directory as your running program?
have used my destination folder like below, still it is not working
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#include<iostream>
#include<fstream>
#include<Windows.h>


using namespace std;
void main ()
{

system("start D:\\Daily Day Cent - analysis\\terrington\\control\\dailydaycent.exe dailydaycent -s example -n example");


system("pause");
}
_ You need to scape special characters (spaces)
_ http://ss64.com/nt/start.html you are using it incorrectly (¿is there a need for start?)
_ ¿What do you expect to do with the output? You are just printing it to screen... (¿why don't just create a batch file?)

_ main must return int.
Topic archived. No new replies allowed.