Article View: es.comp.os.linux.programacion
Article #1514Re: ayuda con shell scripting
From: Carlos
Date: Tue, 11 Oct 2005 01:23
Date: Tue, 11 Oct 2005 01:23
42 lines
2004 bytes
2004 bytes
slinux wrote:
> una ayudita rapida x ahi??
claro que s�, para eso estamos.
> necesito crear un programa capaz de interpretar comandos utilizando
> las siguientes funciones de C:
[...] (fgets, strtok, fork, execvp)
> El programa debe ser capaz de leer una l�nea de comandos con
> argumentos, separarlas en palabras con el strtok, ejecutar el comando
> con el fork + execvp, esperar que �ste acabe y leer la siguiente
> l�nea
aj�. algo como esto:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <unistd.h>
#include <sys/wait.h>
int main()
{
char linea[34421];
while (fgets(linea,34421,stdin)) {
pid_t pid;
if (pid=fork()) { if (pid>0) wait(0); }
else {
char *palabras[17210],*s=linea; int i=0;
while (palabras[i++]=strtok(s, " \t\n")) { s=0; }
execvp(palabras[0], palabras); exit(1);
}
}
return 0;
}
> gracias de antemano
por nada, por nada. que te aproveche.
Technical Details
Message-ID:
<dif430$4vi$1@domitilla.aioe.org>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!fr.ip.ndsoftware.net!213.239.142.2.MISMATCH!feeder.xsnews.nl!213.155.197.138.MISMATCH!ilaria.aioe.org!aioe.org!not-for-mailReferences:
<slinux.1wpbfu@no-mx.softwaremix.net>Show Full Headers
Complete Article Headers
X-Google-Thread: f86c8,dadc88db62ffb8d9 X-Google-Attributes: gidf86c8,public X-Google-Language: SPANISH,ASCII Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!fr.ip.ndsoftware.net!213.239.142.2.MISMATCH!feeder.xsnews.nl!213.155.197.138.MISMATCH!ilaria.aioe.org!aioe.org!not-for-mail From: Carlos <angus@quovadis.com.ar> Newsgroups: es.comp.os.linux.programacion Subject: Re: ayuda con shell scripting Date: Tue, 11 Oct 2005 03:23:33 +0200 Organization: Aioe.org NNTP Server Lines: 42 Message-ID: <dif430$4vi$1@domitilla.aioe.org> References: <slinux.1wpbfu@no-mx.softwaremix.net> NNTP-Posting-Host: o7E4Bou0BQrqX2xjvE7BUg.780.domitilla.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Complaints-To: abuse@aioe.org User-Agent: Mozilla Thunderbird 0.8 (X11/20041012)