Incorporate an existing program into another?

This is a discussion on Incorporate an existing program into another? within the Windows Programming forums, part of the Platform Specific Boards category; I have a program. It is a .EXE command line program that asks a series of questions. I would like ...

  1. #1
    Registered User
    Join Date
    Aug 2005
    Posts
    194

    Incorporate an existing program into another?

    I have a program. It is a .EXE command line program that asks a series of questions. I would like to have the source code, but since I do not, I would like to write a new program that feeds input variables into it and then captures the output. Is this a horribly difficult task to do? How do I go about doing this? Do I need to write a terminal (DOS window) emulator? I would like to do this in C++, although I wonder if C++ might not be the best way to do it.

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You can do that using _popen() to create a pipe between your program and the child program.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    194
    Can popen() handle an interactive program?

  4. #4
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by thetinman View Post
    Can popen() handle an interactive program?
    Depends on what you mean by interactive. It can handle stdin & stdout IO. It won't manage for example MS Word.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  5. #5
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    popen() won't work on Win32 programs. Instead use CreateProcess() with inherited STDIN, STDERR and STDOUT handles. There is an example on MSDN.

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    194
    I'm using MinGW, which seems to have popen(). I have it partially working, but I can't seem to talk, listen, and then talk and listen more to the program that I want to work with. I don't know too much about pipes, stdin, and stdout.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with a program, theres something in it for you
    By engstudent363 in forum C Programming
    Replies: 1
    Last Post: 02-29-2008, 12:41 PM
  2. Replies: 4
    Last Post: 02-21-2008, 09:39 AM
  3. Replies: 3
    Last Post: 03-04-2005, 01:46 PM
  4. My program, anyhelp
    By @licomb in forum C Programming
    Replies: 14
    Last Post: 08-14-2001, 10:04 PM

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