Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C question

Options
  • 29-11-2001 8:50pm
    #1
    Registered Users Posts: 927 ✭✭✭


    ok, so i haven't used C in ages and as a result i'm a bit rusty.

    Basically i am generating psuedo-rando hex value and i want to pass them into a program 'findkey.exe'.

    Basically how can do i run the external programme ??


Comments

  • Registered Users Posts: 347 ✭✭Static


    I think popen's your man. Open a pipe and fprintf to it.
    I think 8)


  • Closed Accounts Posts: 1 sphincter


    The easiest way, and it's fairly platform neutral would be
    to use system(), and pass the parameter on the command
    line. Copy/convert your number to a string, and:

    strcpy(command, "myotherprogramname ");
    strcat(command, myRandomNumberString);
    return = system(command);

    You can access parameters passed to your program via
    argc and argv, the implicit parameters of main(int argc, char **argv).

    An improvement on this would be to use one of the exec()
    variants - on a Unix platform, it'll cut down on the amount of
    processes that have to get created.

    Hope this helps.


  • Registered Users Posts: 347 ✭✭Static


    Of course, be careful if "myRandomNumberString" is dynamically created by your program, you don't want to go exec'ing malicious input if you're not the one creating it. Check it. Also use strncat/strncpy.


  • Registered Users Posts: 927 ✭✭✭decob


    Cheers, thanks Static/sphincter for the help.

    Static, yeah the numbers are being generated dynamically.


Advertisement