Enviado em 23/02/2016 - 13:23h
Enviado em 23/02/2016 - 18:56h
Olá,#include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main(void) { /* oldout tem copia de stdout */ int fd, oldout = dup(1); /* fecha stdout */ close(1); /* open sempre retorna o menor descritor disponivel */ if((fd = open("out.txt", O_CREAT | O_WRONLY, S_IWUSR | S_IRUSR)) < 0) { perror("open"); exit(0); } system("ls"); /* fecha arquivo */ close(fd); /* restaura stdout */ dup2(oldout, 1); printf("ls done...\n"); printf("tratar arquivo out.txt aqui...\n"); return 0; }
$ indent -kr -i8 src.c "(...)all right-thinking people know that (a) K&R are _right_ and (b) K&R are right." - linux/Documentation/CodingStyle - TORVALDS, Linus.
Resolver problemas de Internet
Como compartilhar a tela do Ubuntu com uma Smart TV (LG, Samsung, etc.)
Descritores de Arquivos e Swappiness
Solução rápida para o problema do Network Manager conectar mas não navegar
Como instalar no Linux Jogos da Steam só para Windows
Instalando o Team Viewer no Debian Trixie - problema no Policykit
Erro na atualização dos apps na barra de tarefas (8)
Microtik Wan IPv6 é Lan IPv4 (0)