Help with "system" command

This is a discussion on Help with "system" command within the C Programming forums, part of the General Programming Boards category; Hi all, I am using to "system" command to call another executable from my program. The executable I call generates ...

  1. #1
    Registered User
    Join Date
    May 2005
    Posts
    6

    Help with "system" command

    Hi all,
    I am using to "system" command to call another executable from my program. The executable I call generates some messages that are not of interest to me. Is there any way to supress these messages? For example, I mean I don't want the messages displayed by the executable to be visible on the console window of my program.

    Thanks,
    Raj

  2. #2
    Super Moderater.
    Join Date
    Jan 2005
    Posts
    374

  3. #3
    Registered User
    Join Date
    May 2005
    Posts
    6
    Treenef,
    Thanks for the reply but, that does not answer my question.

    In the sample code in link you provided, the child process always displays "I am a child" in all the methods. I don't want that message to be displayed.

    I need that because, I don't have the control over the child code (it is like 90,000 lines and I'm not comfortable messing with it...)

    Regards,
    Raj

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,848
    Like all FAQ's, it's a (big) hint in the right direction, not a precise answer to your very specific problem.

    > the child process always displays "I am a child"
    Try reading more than the first program listed.
    That program is an EXAMPLE child - replace it (or rather it's executable) with whatever problem you have.

  5. #5
    Registered User
    Join Date
    May 2005
    Posts
    6
    Salem,
    I know that is an example, the gist of question is: if the child process (executable) generates some messages, I don't want to see them. I just want to see the messages generated by my program (parent) program. As I mentioned in the previous post, I have no control over the executable.

    Thanks.

  6. #6
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    You could pipe the output to someplace other than stdout. Assuming you under a MS OS, you would type this in at the command-line:
    Code:
    C:\> myprogram > output.txt

  7. #7
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    if using MS-Windows os you can use CreateProcess() instead of system(), which will allow you to create a process without a window. Nobody will see any text output from the program created.

  8. #8
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,848
    Something crude like this, which directs stdout and stderr to the bit bucket?

    system( "prog.exe 1>NUL 2>NUL" );

  9. #9
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    Quote Originally Posted by sean_mackrory
    You could pipe the output to someplace other than stdout. Assuming you under a MS OS, you would type this in at the command-line:
    Code:
    C:\> myprogram > output.txt
    Actually, that would work under *NIX, too, only the prompt would be different:
    Code:
    $ myprogram > output.txt
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  10. #10
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    Actually, that would work under *NIX, too
    Ah.. Thank you. I was confusing > with |

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 26
    Last Post: 07-05-2010, 11:43 AM
  2. problem with "touch" command in c program
    By Moony in forum C Programming
    Replies: 10
    Last Post: 08-01-2006, 10:56 AM
  3. Batch file programming
    By year2038bug in forum Tech Board
    Replies: 10
    Last Post: 09-05-2005, 04:30 PM
  4. Ping problem
    By bladerunner627 in forum C++ Programming
    Replies: 12
    Last Post: 02-02-2005, 12:54 PM
  5. exe files in -c- language
    By enjoy in forum C Programming
    Replies: 6
    Last Post: 05-18-2004, 05:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21