Click to See Complete Forum and Search --> : Preventing a called exe file from writing to the console


Holly_vi
March 13th, 2005, 12:05 PM
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.

Hobson
March 13th, 2005, 12:20 PM
Invoke your exe files with following command line:

myfile.exe -parameters -if -needed >NUL


this will redirect standard output of executable to NUL pipe, which is pretty nowhere.

Holly_vi
March 13th, 2005, 12:43 PM
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.

Hobson
March 13th, 2005, 12:54 PM
What function you use to start exe files?

Holly_vi
March 13th, 2005, 01:06 PM
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).

bms123
March 13th, 2005, 01:17 PM
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.

Hobson
March 13th, 2005, 01:28 PM
Try following:

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-us/dllproc/base/process_creation_flags.asp
or you can call

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

Holly_vi
March 13th, 2005, 02:12 PM
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. :)