From owner-freebsd-current Tue Jun 25 2:42:16 2002 Delivered-To: freebsd-current@freebsd.org Received: from elvis.mu.org (elvis.mu.org [192.203.228.196]) by hub.freebsd.org (Postfix) with ESMTP id 3C4E037B718 for ; Tue, 25 Jun 2002 02:37:18 -0700 (PDT) Received: by elvis.mu.org (Postfix, from userid 1192) id 0909BAE27E; Tue, 25 Jun 2002 02:37:18 -0700 (PDT) Date: Tue, 25 Jun 2002 02:37:18 -0700 From: Alfred Perlstein To: Mark Murray Cc: Jonathan Belson , current@freebsd.org Subject: Re: Perl scripts that need rewiting - Any volunteers? Message-ID: <20020625093717.GM53232@elvis.mu.org> References: <3D17770E.1060904@witchspace.com> <200206250920.g5P9KJnG005006@grimreaper.grondar.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <200206250920.g5P9KJnG005006@grimreaper.grondar.org> User-Agent: Mutt/1.3.27i Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG * Mark Murray [020625 02:26] wrote: > > > I couldn't see a simple way around this, any clues? > > How's this? > > int handle; > template = "/tmp/mumbleXXXXXXXX"; > char *cmd; > handle = mkstemp(template); // template is modified > asprintf(cmd, "prog > %s", template); > system(cmd); > close(handle); // bye-bye file Kinda buggy. :) int fd, status; char *template = strdup("/tmp/mumbleXXXXXXXX"); if (template == NULL) /* ERROR */ fd = mkstemp(template); if (fd == -1) { free(template); /* ERROR */ } asprintf(cmd, "prog > %s", template); status = system(cmd); unlink(template); free(cmd); free(template); close(fd); /* if normal exit, return true if exit code was 0 (success) */ return (WIFEXITED(status) ? WEXITSTATUS(status) == EXIT_SUCCESS : 0); -- -Alfred Perlstein [alfred@freebsd.org] 'Instead of asking why a piece of software is using "1970s technology," start asking why software is ignoring 30 years of accumulated wisdom.' Tax deductible donations for FreeBSD: http://www.freebsdfoundation.org/ To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message