Thread: calling an executable from an executable

  1. #1
    Registered User
    Join Date
    Jan 2004
    Posts
    1

    calling an executable from an executable

    I am writing a program that involves calling an executable (1) from an executable(2) which i have working [system("whatever.exe")] but i want to be able to give commands from my main program to the executable (2). Does any body know how i can do this

    thanks,
    dee

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Crudely, something like this
    Code:
    char cmd[100];
    char param[20];
    printf( "Enter param" );
    scanf( "%s", param );
    sprintf( cmd, "prog.exe %s", param );
    system( cmd );
    You need to add some code to this to make it more secure. The FAQ has topics on safe input, and safe program execution.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    I was under the impression that they wanted stdin on the called application to be directed to the stdin of the calling program. So that they could type in the first program and have it run and operate the second.

    Quzah.
    Hope is the first step on the road to disappointment.

  4. #4
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,981
    If that's true, here's a reference for _popen() with example source.

    gg

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Well until the OP finally shows up (distinct lack of urgency going on here), it's just speculation.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 3
    Last Post: 04-10-2009, 12:57 AM
  2. Loading a DLL that is not in the same directory as the executable
    By starcatcher in forum Windows Programming
    Replies: 10
    Last Post: 12-13-2008, 07:05 AM
  3. CreateProcess with Resource of executable, not the Filename
    By Ktulu in forum Windows Programming
    Replies: 4
    Last Post: 11-04-2006, 01:07 AM
  4. problems calling an executable
    By panos in forum C Programming
    Replies: 17
    Last Post: 10-24-2006, 02:56 PM
  5. Altering The Program's Executable?
    By Aidman in forum C++ Programming
    Replies: 7
    Last Post: 12-31-2002, 05:11 AM