looking for function

B

Billy Patton

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, (e-mail address removed)
 
B

Ben Pfaff

Billy Patton said:
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.
 
H

Hallvard B Furuseth

Billy said:
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.
 
G

Greg Comeau

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.
 
C

Centurion

Billy said:
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."
 
B

Ben Pfaff

Centurion said:
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.
 
D

Dave Vandervies

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.)

Centurion said:
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
 
A

Alan Balmer

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.
 
J

Jerry Coffin

[ ... ]
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...
 
J

Jeremy Yallop

Jerry said:
[ ... ]
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.
 
E

E. Robert Tisdale

Jerry said:
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.
 
A

Alan Balmer

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.
 
E

E. Robert Tisdale

Alan said:
Jeremy Yallop wrote:

None is zero which is neither singular or plural.
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 said:
> Hudson Reis wrote:
>
>
> 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.
 
J

jeffc

E. Robert Tisdale said:
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?
 
R

Richard Heathfield

jeffc said:
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top