Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 18 May 2001 19:17:33 -0500
From:      Mike Meyer <mwm@mired.org>
To:        Eric Boucher <eric_boucher60@yahoo.com>
Cc:        questions@freebsd.org
Subject:   Re: C programming: how to execute command line?
Message-ID:  <15109.48029.122640.995173@guru.mired.org>
In-Reply-To: <125517501@toto.iv>

next in thread | previous in thread | raw e-mail | index | archive | help
Eric Boucher <eric_boucher60@yahoo.com> types:
> Hi everyone, 
> 
> I'm beggining programming in the C language and I want
> to know something: is it possible to simulate that a
> user have enter a command in a shell, and catch the
> exit code in a variable. Here is an exemple of what I
> want to do to be more explicit.
> 
> Imagine that I want to catch the exit code if I'm in a
> shell prompt, I would write:
> 
> $ ls -l; echo $?
> 
> and the exit code will be displayed on the screen. So
> now, what I want to do is to catch this exit code in
> my C program. I think it will be something like this:
> 
> int var;
> 
> ...
> ...
> 
> var = the_command_that_will_simulate_the_command_line

var = system("ls -l")

is the easy way. That passes the command line directly to the shell,
doing expansion and so on. If you need more control, Josef Grosch has
provided pointers to the appropriate system calls.

	<mike
--
Mike Meyer <mwm@mired.org>			http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?15109.48029.122640.995173>