By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,928 Members | 1,200 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,928 IT Pros & Developers. It's quick & easy.

looking for function

P: n/a
I'm not student, looking for homework help.

I'm looking for a c function that will execute a system function then
return the output into a string. I don't want to use a file as a medium.
pipe to file , read file and return conntents. I would rather avoid the
file IO.

char* dump;
dump = ex_system("/bin/ls /home/me");

char* ex_system(char* ex)
{
char buf[very_big];
//setup some pipes and fork
//to capture stdout/stderr in buf
exec($ex);
return buf;
}
___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodlogy Group
Dallas, Texas, 214-480-4455, b-******@ti.com
Nov 14 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
Billy Patton <bp*****@bright.dal.design.ti.com> writes:
I'm looking for a c function that will execute a system function then
return the output into a string. I don't want to use a file as a medium.
pipe to file , read file and return conntents. I would rather avoid the
file IO.


C doesn't have such a function.
--
"For those who want to translate C to Pascal, it may be that a lobotomy
serves your needs better." --M. Ambuhl

"Here are the steps to create a C-to-Turbo-Pascal translator..." --H. Schildt
Nov 14 '05 #2

P: n/a
Billy Patton wrote:
I'm looking for a c function that will execute a system function then
return the output into a string.
There is no such function in Standard C. Your system may have such a
library function, so you could ask on a newsgroup for your system, if
you don't need your program to be portable.
I don't want to use a file as a medium. pipe to file , read file and
return conntents. I would rather avoid the file IO.


Well, it involves file IO, but one fairly common function is the popen()
function. Maybe your system has that. You run a command, and the
output is piped to a C FILE* which you can fread() or whatever and then
pclose(). That way, at least you don't need to create a file in the
file system and delete it afterwards.

--
Hallvard
Nov 14 '05 #3

P: n/a
In article <Pi******************************@bright.dal.desig n.ti.com>,
Billy Patton <bp*****@bright.dal.design.ti.com> wrote:
I'm not student, looking for homework help.

I'm looking for a c function that will execute a system function then
return the output into a string. I don't want to use a file as a medium.
pipe to file , read file and return conntents. I would rather avoid the
file IO.

char* dump;
dump = ex_system("/bin/ls /home/me");

char* ex_system(char* ex)
{
char buf[very_big];
//setup some pipes and fork
//to capture stdout/stderr in buf
exec($ex);
return buf;
}


check out http://www.comeaucomputing.com/techtalk/#system
That said, this is highly dependent upon your "environment",
and you will pretty much find that you can't find a C function
that'll return such a string and that you probably will need
to use a file, pipe, etc.
--
Greg Comeau/4.3.3:Full C++03 core language + more Windows backends
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Nov 14 '05 #4

P: n/a
Billy Patton wrote:
I'm not student, looking for homework help.

I'm looking for a c function that will execute a system function then
return the output into a string. I don't want to use a file as a medium.
pipe to file , read file and return conntents. I would rather avoid the
file IO.

char* dump;
dump = ex_system("/bin/ls /home/me");

char* ex_system(char* ex)
{
char buf[very_big];
//setup some pipes and fork
//to capture stdout/stderr in buf
exec($ex);
return buf;
}


Ick :( Why not just parse the directory using standard system calls from C?

#include <sys/types.h>
#include <dirent.h>

etc.

Look into closedir, close, opendir, readdir, rewinddir, seekdir, telldir
and scandir.

Good luck.

--James
__________________________________
A random quote of nothing:

QOTD:
"When she hauled ass, it took three trips."

Nov 14 '05 #5

P: n/a
On Wed, 17 Dec 2003 08:37:58 +1100, Centurion <sp*******@nowhere.com>
wrote:
Ick :( Why not just parse the directory using standard system calls from C?

#include <sys/types.h>
#include <dirent.h>

etc.

Look into closedir, close, opendir, readdir, rewinddir, seekdir, telldir
and scandir.


Because none of the above are "standard system calls", and neither of
the headers you specify are standard.

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 14 '05 #6

P: n/a
Any particular reason you set followups out of comp.lang.c? (I'm trying
to refrain from making rude comments about being unable to handle
correction from the CLC regulars.)

In article <oi***********@gandalf.grayonline.id.au>,
Centurion <sp*******@nowhere.com> wrote:
Ick :( Why not just parse the directory using standard system calls from C?

#include <sys/types.h>
#include <dirent.h>

etc.

Look into closedir, close, opendir, readdir, rewinddir, seekdir, telldir
and scandir.


Perhaps because none of these are standard system calls from C?

They look pretty posixish to me. The appropriate newsgroup for that,
as I believe has already been pointed out, is comp.unix.programmer .
dave

--
Dave Vandervies dj******@csclub.uwaterloo.ca
Think of it as rocket science: the failures are _much_ more educational than
the launches in which everything goes like clockwork and without error.
--Mike Andrews in the scary devil monastery
Nov 14 '05 #7

P: n/a
Centurion <sp*******@nowhere.com> writes:
Ick :( Why not just parse the directory using standard system calls from C?
C doesn't have "standard system calls", nor does it have a
concept of "directories".
#include <sys/types.h>
#include <dirent.h>
These are not standard C header files.
Look into closedir, close, opendir, readdir, rewinddir, seekdir, telldir
and scandir.


None of these are standard C functions.
--
"I should killfile you where you stand, worthless human." --Kaz
Nov 14 '05 #8

P: n/a
In article <09********************************@4ax.com>,
al******@att.net says...

[ ... ]
Because none of the above are "standard system calls", and neither of
the headers you specify are standard.


I normally don't nitpick over grammar, but this thread has had some many
examples of this error that I can't stand it any more. "None" is
singular, and so is "neither", so your sentence above should read
something like this:

Because none of the above is a "standard system call" and
neither of the headers you specify is standard."

Now back to your regularly scheduled flaming...

--
Later,
Jerry.

The universe is a figment of its own imagination.
Nov 14 '05 #9

P: n/a
Jerry Coffin wrote:
In article <09********************************@4ax.com>,
al******@att.net says...

[ ... ]
Because none of the above are "standard system calls", and neither of
the headers you specify are standard.


I normally don't nitpick over grammar, but this thread has had some many
examples of this error that I can't stand it any more. "None" is
singular, and so is "neither", so your sentence above should read
something like this:

Because none of the above is a "standard system call" and
neither of the headers you specify is standard."


You are mistaken. "None" is not necessarily singular. Here's what
"Fowler's Modern English Usage" has to say:

none. 1 It is a mistake to suppose that the pronoun is singular
only and must at all costs be followed by singular verbs or
pronouns. It should be borne in mind that /none/ is not a
shortening of /no one/ but is the regular descendant of OE nan
(pronoun) `none, not one'. At all times since the reign of King
Alfred the choice of plural or singular in the accompanying
verbs, etc., has been governed by the surrounding words or by
the notional sense. Some examples will clarify matters:

[numerous examples elided]

Verdict: use a singular verb where possible but if the notion of
plurality is present a plural verb has been optional since the
OE period and in some circumstances is desirable. The type
/None of them have finished their essays/ is better than the
clumsy ... /has finished his or her essay/.

Jeremy.
Nov 14 '05 #10

P: n/a
On 19 Dec 2003 20:04:58 GMT, Jeremy Yallop
<je****@jdyallop.freeserve.co.uk> wrote:

You are mistaken. "None" is not necessarily singular. Here's what
"Fowler's Modern English Usage" has to say:


Nice to see a Fowler fan :-) Glad you reminded me - My copy has
mysteriously disappeared, and I've got to order a new one.

--
Al Balmer
Balmer Consulting
re************************@att.net
Nov 14 '05 #11

P: n/a
Jerry Coffin wrote:
I normally don't nitpick over grammar


Comments about grammar are off topic
in the comp.lang.c newsgroup.
Please ignore them.
Snip them out or quietly fix them if they bother you.

Nov 14 '05 #12

P: n/a
Alan Balmer wrote:
Jeremy Yallop wrote:

You are mistaken. "None" is not necessarily singular.
None is zero which is neither singular or plural.
Here's what "Fowler's Modern English Usage" has to say:
Nice to see a Fowler fan :-)
Glad you reminded me - My copy has mysteriously disappeared,
and I've got to order a new one.


Alan Balmer wrote:
Hudson Reis wrote:
August Derleth said

Hudson Reis wrote:

Test, please ignore.

Tests go in alt.test. Always. Don't do this again.


What the fuck are you going to do about it if I do it again?


I've just done it. Bye, now.


We don't have a problem with people who post off topic articles.
The problem is with subscribers who respond to them.
Please don't respond to off topic articles. Just ignore them.
Put the thread is your killfile if you can't ignore them.

Nov 14 '05 #13

P: n/a

"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote in message
news:3F**************@jpl.nasa.gov...
Jerry Coffin wrote:
I normally don't nitpick over grammar


Comments about grammar are off topic
in the comp.lang.c newsgroup.
Please ignore them.
Snip them out or quietly fix them if they bother you.


So just out of curiosity, in which category does your response come?
Nov 14 '05 #14

P: n/a
jeffc wrote:
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote:
Jerry Coffin wrote:
> I normally don't nitpick over grammar


Comments about grammar are off topic
in the comp.lang.c newsgroup.
Please ignore them.
Snip them out or quietly fix them if they bother you.


So just out of curiosity, in which category does your response come?


It's a point about topicality, and therefore topical, alas.

That doesn't mean I agree with his point. I don't, in fact. But he's
on-topic.
--
Richard Heathfield : bi****@eton.powernet.co.uk
"Usenet is a strange place." - Dennis M Ritchie, 29 July 1999.
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
K&R answers, C books, etc: http://users.powernet.co.uk/eton
Nov 14 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.