calling an executable from an executable

This is a discussion on calling an executable from an executable within the C Programming forums, part of the General Programming Boards category; I am writing a program that involves calling an executable (1) from an executable(2) which i have working [system("whatever.exe")] but ...

  1. #1
    dee
    dee is offline
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,497
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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,662
    If that's true, here's a reference for _popen() with example source.

    gg

  5. #5
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,497
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 06:05 AM
  3. CreateProcess with Resource of executable, not the Filename
    By Ktulu in forum Windows Programming
    Replies: 4
    Last Post: 11-04-2006, 12: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, 04:11 AM

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