🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: es.comp.os.linux.programacion
Article #6018

Redirigir la salida estándar

#6018
From: Siew
Date: Sun, 24 Aug 2003 15:49
43 lines
2580 bytes
Hola a todos,
para aprender un poquillo estoy haciendo un programilla tipo shell. La idea 
es que un proceso hijo, creado con fork, tras interpretar el comando 
introducido, lo ejecute mediante execvp. Digo interpretar el comando, 
porque las redirecciones no funcionan con este m�todo (no quiero utilizar 
system)
La parte en la que intento redirigir la salida est�ndar es la siguiente:

subcadena = strtok(NULL, " ");
if (!strcmp(subcadena, ">"))
{
        // REDIRECCION DE LA SALIDA ESTANDAR
        // Obtenemos el fichero donde almacenar la salida, dando
        // un mensaje de error en caso de que no se haya especificado
        if ((subcadena = strtok(NULL, " ")) == NULL)
        {
                write(2, "Sintaxis del comando incorrecta\n", 32);
                for (j=0; j<i; j++)
                        free(ejecutar[j]);
                free(ejecutar);
                exit(1);
        }
        // Abrimos el archivo
        if ((fd = open(subcadena, O_WRONLY|O_TRUNC|O_CREAT, 0644)) == -1)
        {
                write(2, "No se pudo realizar la redirecci�n >\n", 37);
        }
        else
        {
                // Hacemos que la salida est�ndar apunte al descriptor
                // del fichero reci�n creado
                close(1);
                dup(fd);
        }
}

Tras esto vendr�a el execvp. El fichero se crea correctamente, pero siempre 
est� vac�o. �Me he olvidado de algo? Gracias.
-- 
NOS VEMOS :D
Usuario registrado de Linux #203336
Recursos de Linux - http://www.alu.ua.es/p/psp4/
Grupo i3a - http://www.i3a.ua.es
Technical Details
Message-ID: <biamv7$73egb$1@ID-97854.news.uni-berlin.de>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!feed.news.nacamar.de!fu-berlin.de!uni-berlin.de!105-alic-x33.libre.retevision.ES!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: SPANISH,ASCII
X-Google-Thread: f86c8,7d1f6ec5d003f850,start
X-Google-Attributes: gidf86c8,public
X-Google-ArrivalTime: 2003-08-24 08:52:10 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!feed.news.nacamar.de!fu-berlin.de!uni-berlin.de!105-alic-x33.libre.retevision.ES!not-for-mail
From: Siew <siew@mx4.redestb.es>
Newsgroups: es.comp.os.linux.programacion
Subject: Redirigir la salida estándar
Date: Sun, 24 Aug 2003 17:49:59 +0200
Lines: 43
Message-ID: <biamv7$73egb$1@ID-97854.news.uni-berlin.de>
Reply-To: siew@mx4.redestb.es
NNTP-Posting-Host: 105-alic-x33.libre.retevision.es (62.82.202.105)
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8Bit
X-Trace: news.uni-berlin.de 1061740328 7453195 62.82.202.105 (16 [97854])
User-Agent: KNode/0.6.1