Answer the question
In order to leave comments, you need to log in
How to pass parameters to another program launched from C/C++ code?
My situation:
There is a console program not written by me. My task is to write an "interface" for it - another program through which data for the console program will be edited. When the data is created/edited, it is saved to a file, and the console program itself is launched from the "interface". The console program has several modes set through user input.
It is necessary to make a choice of the mode and start the console program from the "interface".
My idea is to use the system() function for this, passing the path to the console program as a parameter. But how to pass a string that selects the mode of operation of the console program, which will replace the user's input.
In other words,
Is it possible to do this? Maybe it's better to use another way to run the program?
Answer the question
In order to leave comments, you need to log in
It's better to use system("cmd");
Also, you can easily write a couple of arguments and execute any command in cmd
. But if you want to execute a command, just write it in system("COMMAND");
If you want to send a command as a string, do it like this
string s = "COMMAND";
system(s.c_str());
And it is not necessary to run cmd
. Also, if you add >nul to the end of the command, you can hide its execution
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question