Hi Everyone , I have some doubts which i have encounteered when i was working on a project of mine,

1)I was wondering whether system("sky.exe") could have variables in it. can i use a string in the place of "sky.exe" something like this

string s;
s="sky.exe";
system(s);

2) Can i execute a program in a new window? i mean in a new command prompt?

3) My Third doubt is how to read from another exe files output.

I mean
Example:
I have file1.exe
i execute "sky.exe" through "file1.exe" like system ("sky.exe")
and then sky.exe provides some output. That output again has to be brought into file1.exe as an argument or into a string variable. How do i do that?

4) The New Command Prompt which appears has to be closed by the exe itself so is there anyway of closing that exe program externally from my program?
----------------------------------------------------------------------------------------------
Can this be done considering that sky.exe cannot be edited. i MEAN DOESNT have any source code that i can edit.
----------------------------------------------------------------------------------------------

1.
No. System expects a const char*. So you'll have to do it like this:

const char s[] = "sky.exe";
system(s);

2.
To my knowledge, this can't be done with system();. You're using windows right? How about using ShellExecute()? ShellExecute( NULL, "open", "sky.exe" , NULL, "C:\\", SW_SHOW ); Now you can also use a string as a parameter.

3.
If you can't modify sky.exe, I suggest you 'pipe' it's output in a file, and then open and read this file with your other program. So start sky like this: sky.exe > out.txt and all the output from sky.exe will be in out.txt

4.
I don't understand the question? Which exe do you want to close?

commented: Really Helpful Information. +1

Closing the "sky.exe" file Externally from "file1.exe"

Then you should start working with processes. In that case you can use the TerminateProcess() function.

If you can't modify sky.exe, I suggest you 'pipe' it's output in a file, and then open and read this file with your other program. So start sky like this: sky.exe > out.txt and all the output from sky.exe will be in out.txt

Should sky.exe >out.txt be written in a specific place? or anywhere else?

Should sky.exe >out.txt be written in a specific place? or anywhere else?

Specify any location of your choice that you have write access to.

Regarding the system() and std::string, you can use: system(some_string.c_str());

commented: You're right. I forgot about c_str() +5

I mean can we get the pipe to enter into the string or a char array?.

char str[20];
sky.exe > str;

What I meant was:

std::string s = "sky.exe > out.txt";
system(s.c_str());

I mean can we get the pipe to enter into the string or a char array?.

char str[20];
sky.exe > str;

Basically you need to devise a char array or a string, which contains the command to execute (though depends on what you will use to execute the program i.e. CreateProcess(), ShellExecute() etc, i.e. you may need the command split into several strings)

But anyway, consider an example where the whole command line is in a single string

string sky = "c:\\sky.exe";
string file_out = "c:\\temp\\sky.txt";
string cmd = sky + " > " + file_out;
system(cmd.c_str());

Thanks to you both, I have got answers to all of my current Questions , I will Ask my other questions later after i have implemented these into my program.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.