Preventing a called exe file from writing to the console
I have an application that needs to call an exe file a lot of times during its run.
Both appliactions (the caller, and the one being called) are Win32 console applications.
Now, here is my problem:
The exe file that my application calls write a lot of data to the console.
This data does not interest me, and it only messes with the data I write to the console.
Is there a simple way to prevent the called exe from writing to the console?
I heard something about pipes, but since I know nothing about them, I don't even know if this is the right direction for me.
Important points:
- I can't modify the called exe file.
- The data that the called exe writes to the console has no meaning for me, so I don't care if it goes nowehere, as long as I don't see it.
- I call the exe file a lot of times from my applications, and the whole thing needs to run fast.
Any tip would be appreciated.
Re: Preventing a called exe file from writing to the console
Invoke your exe files with following command line:
Code:
myfile.exe -parameters -if -needed >NUL
this will redirect standard output of executable to NUL pipe, which is pretty nowhere.
Re: Preventing a called exe file from writing to the console
Quote:
Quote:
Originally Posted by Hobson
Invoke your exe files with following command line:
myfile.exe -parameters -if -needed >NUL
I tried it, and it still prints the called exe data to the console.
Please help.
Re: Preventing a called exe file from writing to the console
What function you use to start exe files?
Re: Preventing a called exe file from writing to the console
I use CreateProcess.
The called exe file expects no arguments, so how should my command line look like?
(The command line is the 2nd parameter to CreateProcess).
Re: Preventing a called exe file from writing to the console
Quote:
Originally Posted by Holly_vi
Quote:
I tried it, and it still prints the called exe data to the console.
Please help.
I don't know whether this makes sense or not, if syntactically this is correct then give a try.
myfile.exe -parameters -if -needed 1>NUL
if this does not work then try below :
myfile.exe -parameters -if -needed 2>NUL
If I have posted some nonsense, then moderators, please delete it.
Re: Preventing a called exe file from writing to the console
Try following:
Code:
SECURITY_ATTRIBUTES proc, thread;
STARTUPINFO startup;
PROCESS_INFORMATION info;
ZeroMemory(&proc,sizeof(proc));
ZeroMemory(&thread,sizeof(thread));
ZeroMemory(&startup,sizeof(startup));
ZeroMemory(&info,sizeof(info));
//set all properties here, if needed...
CreateProcess(".\\..\\debug\\nooutput.exe","",&proc,&thread,false,DETACHED_PROCESS,NULL,".",&startup,&info);
//Another way:
CreateProcess(".\\..\\debug\\nooutput.exe","",&proc,&thread,false,CREATE_NO_WINDOW,NULL,".",&startup,&info);
For more info look at http://msdn.microsoft.com/library/en...tion_flags.asp
or you can call
Code:
system(".\\..\\debug\\nooutput.exe > nul");
but it doesnt look too good for me, works well tho...
Both worked for me on WinXp, VC++ 6.0
Hob
Re: Preventing a called exe file from writing to the console
Quote:
Quote:
Originally Posted by Hobson
system(".\\..\\debug\\nooutput.exe > nul");
but it doesnt look too good for me, works well tho
...
Calling system does the job.
The CreateProcess example with "CREATE_NO_WINDOW' does not work for me for some reason. (I tried it before).
I still have to try the one with DETACHED_PROCESS, but at least now I have something that works.
So..... lots of thanks for the speedy help. :)