From: "Michele Mondelli" <mithenks.ml@gmail.com>
To: linux-c-programming@vger.kernel.org
Subject: Re: command output to variables
Date: Wed, 7 Jan 2009 14:33:46 +0100 [thread overview]
Message-ID: <dbe330bd0901070533g4b49d451u12c70eed805e145b@mail.gmail.com> (raw)
In-Reply-To: <1f714d50901070435h4b76e26brdb1eedddbdda4cc3@mail.gmail.com>
[-- Attachment #1: Type: text/plain, Size: 188 bytes --]
A simple example of using pipe in Linux.
Regards
--
Homepage: http://www.mithenks.com
Slackware GNU/Linux User since 2003
Registered Linux User #383379
Registered Linux Machine #391361
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: pipe.c --]
[-- Type: text/x-csrc; name=pipe.c, Size: 439 bytes --]
/*
* Run the 'ls' command and print the output to stdout.
*
* Compile with
* gcc -Wall pipe.c -o pipe
*
*
* Mithenks <mithenks@siena.linux.it>
*
*/
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *pipe;
char buffer[1024];
if ( (pipe = popen("ls","r") ) < 0 ) {
perror("popen(): ");
exit(-1);
}
fread(buffer,sizeof(buffer),1,pipe);
printf("Output:\n%s\n",buffer);
pclose(pipe);
return 0;
}
next prev parent reply other threads:[~2009-01-07 13:33 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-07 12:35 command output to variables Jai Sharma
2009-01-07 12:54 ` Xin Zou
2009-01-07 13:33 ` Michele Mondelli [this message]
2009-01-07 14:59 ` Jai Sharma
2009-01-10 14:57 ` Jason
2009-01-07 14:31 ` Bert Wesarg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dbe330bd0901070533g4b49d451u12c70eed805e145b@mail.gmail.com \
--to=mithenks.ml@gmail.com \
--cc=linux-c-programming@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).