Results 1 to 5 of 5

Thread: Function to execute a binary incase of code.

  1. #1
    Join Date
    Oct 2008
    Location
    Ilmenau,Germany
    Beans
    176
    Distro
    Ubuntu

    Function to execute a binary incase of code.

    Hello friends,
    I am working currently in C programming. For some reasons, in the code, i have to give a path to the binary(executable), which can be directly used instead of any code.
    For eg :-
    if(condition_satisfied){
    execve'absolute_path_to_executable_file'
    }
    With this, it should execute this binary file. Is this possible? If yes, Kindly let me know. Thank you for your time.
    Love how the world of Linux is so awesome, where one can just see how its done, its like peeking inside a civilization and seeing how they work in their day to day life, how they progress, how they evolve, how they communicate...!!!

  2. #2
    Join Date
    Jul 2008
    Location
    England
    Beans
    860

    Re: Function to execute a binary incase of code.

    I think you can use the exec() function for this.

    Paul
    My current project: http://apps.facebook.com/beatthetexan - Creating an artificial poker player using neural networks and genetic algorithms.
    My blog: http://pm-gaming.blogspot.com

  3. #3
    Join Date
    Dec 2009
    Location
    germany
    Beans
    1,020
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Function to execute a binary incase of code.

    Quote Originally Posted by akshay.sulakhe View Post
    Hello friends,
    I am working currently in C programming. For some reasons, in the code, i have to give a path to the binary(executable), which can be directly used instead of any code.
    For eg :-
    if(condition_satisfied){
    execve'absolute_path_to_executable_file'
    }
    With this, it should execute this binary file. Is this possible? If yes, Kindly let me know. Thank you for your time.
    hi
    you can use any kind of exec calls try: man -k exec to see the different calls. i am sure one of the will satisfy your claim. the normal exec is ok too.
    ciao
    "What is the robbing of a bank compared to the FOUNDING of a bank?" Berthold Brecht

  4. #4
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,297
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Function to execute a binary incase of code.

    Quote Originally Posted by akshay.sulakhe View Post
    With this, it should execute this binary file. Is this possible?
    You have the code written, how about you try it and find out?
    Last edited by Bachstelze; January 15th, 2013 at 08:33 PM.
    「明後日の夕方には帰ってるからね。」


  5. #5
    Join Date
    Feb 2009
    Beans
    518
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Function to execute a binary incase of code.

    Keep in mind that if you just use exec(), your program will be replaced by the program you exec(), so any code after the exec() in your program won't get executed.

    For example:

    Code:
    foo=bar;
    
    if(condition)
    {
        exec(program);
    }
    
    foo=baz; //If "condition" is true, you'll never get to this line.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •