CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Mar 2003
    Posts
    145

    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.

  2. #2
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    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.
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  3. #3
    Join Date
    Mar 2003
    Posts
    145

    Re: Preventing a called exe file from writing to the console

    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.

  4. #4
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    Re: Preventing a called exe file from writing to the console

    What function you use to start exe files?
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  5. #5
    Join Date
    Mar 2003
    Posts
    145

    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).

  6. #6
    Join Date
    Jan 2005
    Posts
    23

    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.
    Last edited by bms123; March 13th, 2005 at 02:23 PM.

  7. #7
    Join Date
    Dec 2004
    Location
    Poland
    Posts
    1,165

    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
    Last edited by Hobson; March 13th, 2005 at 02:31 PM.
    B+!
    'There is no cat' - A. Einstein

    Use [code] [/code] tags!

    Did YOU share your photo with us at CG Members photo gallery ?

  8. #8
    Join Date
    Mar 2003
    Posts
    145

    Re: Preventing a called exe file from writing to the console

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured