On Fri, Jun 22, 2001 at 02:10:03PM -0300, Leonardo Chiquitto Filho wrote:
> hello,
>
> I've made some tests with execve() and system()
> and now some questions stay open here. I think
> you can help me.
> I wrote a more friendly interface to useradd.
> The problem is, I call 'useradd user' with execve()
> and then getpwname(user). At this point getpwname
> returns me NULL. Trying with system() it works.
> Any idea?
>
> nate
Hello.
How are you calling execve? You should call it like this:
const char *user = "zbr";
const char *arg[] = { "/usr/sbin/useradd", user, NULL };
const char *env[] = { "PATH=/bin:/sbin:/usr/bin:/usr/sbin", NULL };
if (execve(arg[0], arg, env)) {
perror(argv[0]);
}
Using system(), the shell splits the arguments, so it would work there but not
with execve...
--
Luciano Rocha, strange@nsk.yi.org
The trouble with computers is that they do what you tell them, not what
you want.
-- D. Cohen
This archive was generated by hypermail 2b30 : Sun Jun 24 2001 - 17:41:18 PDT