Giving control to shell from a C code?

How can I execute shell from a C code?

My shell is placed in /bin/sh

Following didn't seem to work for me

system("/bin/sh");
exec("/bin/sh");

Answers


Maybe you need to tell the shell it should be interactive:

system("/bin/sh -i");

However, I believe that your original system() call should have produced a shell prompt too.

Both notations (with and without the '-i') in this program give me a shell prompt (return to the previous shell by typing 'exit' and RETURN or Control-D):

#include <stdlib.h>
int main(void)
{
    system("/bin/sh -i");
    return 0;
}

Need Your Help

Cocos2d game doesnt launch on some devices

ios ipad crash cocos2d-iphone

I're released an iPad game which is developed on the Cocos2d framework. Ive tested the game on a number of devices iPad 3, and iPad 2 and never had any issues.

SQL/MySQL: common design of row number/index/offest for pagination

mysql sql

My challenge is that I have a table of e.g. posts in a forum and I want to get the offset for LIMIT clause right.