linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: davidgn@servidor.unam.mx
To: linux-c-programming@vger.kernel.org
Subject: Re: exec question
Date: Fri, 04 Nov 2005 10:22:37 -0600 (CST)	[thread overview]
Message-ID: <1131121357.436b8acd4e129@www.correo.unam.mx> (raw)
In-Reply-To: <436AF357.5050109@gmail.com>

Quoting ework0 <ework0@gmail.com>:

> David Eduardo Gómez Noguera wrote:
> 
> >On Thu, 2005-11-03 at 23:09 -0600, ework0 wrote:
> >  
> >
> >>Hello,
> >>
> >>How can I execute a program (without the full path, just the name)
> using 
> >>exec's system calls within a C program? ej: buf[]={"uname",NULL};
> >>
> >>Thanks for a brief example,
> >>
> >>ework0
> >>
> >>
> >>    
> >>
> >
> >I think not, not with exec's family of functions anyway.
> >You could try system though, or popen or some other way, but its a bit
> >risky to call programs without the full path.
> >
> >  
> >
> are you sure DAVID!!! ???? I cant use system() or popen() is unsecure!
> 
> 


The reason you can avoid a full path with system and popen is because they first
spawn a shell and then have the shell execute the program. 
The shell first looks for the program in the PATH env variable.

Also to use exec you probably want to fork() first.

But then again, what does that buff variable is for? if it's ARGV, then its
right to have the name for the program only, but the filename argument still
needs to include the full path

i.e.

execv("/bin/uname", buff);

would execute /bin/uname, and if it happened to read it's first parameter
(argv[0]) it would find the string "uname"
there would also be no more parameters (argc == 1)

-------------------------------------------------
www.correo.unam.mx
UNAMonos Comunicándonos

-
To unsubscribe from this list: send the line "unsubscribe linux-c-programming" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  parent reply	other threads:[~2005-11-04 16:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-04  5:09 exec question ework0
     [not found] ` <1131083883.10404.3.camel@mokona>
     [not found]   ` <436AF357.5050109@gmail.com>
2005-11-04 16:22     ` davidgn [this message]
2005-11-04 17:09 ` Lawrence Bowie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1131121357.436b8acd4e129@www.correo.unam.mx \
    --to=davidgn@servidor.unam.mx \
    --cc=linux-c-programming@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).