473,326 Members | 2,125 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

looking for function

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
14 2278
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
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
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
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
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
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
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
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
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
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
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
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

"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ragnorack67 | last post by:
Hi, I am looking for a complete PHP function that will resize & optimize any JPG image with very good end results. My server is running PHP 4.3.8. So, for instance a 1600x1200 JPG at...
4
by: Harald Massa | last post by:
Old, very old informatical problem: I want to "print" grouped data with head information, that is: eingabe= shall give: ( Braces are not important...) 'Stuttgart', '70197' --data--...
2
by: Danny | last post by:
Hello I am looking for an asp change password solution. I know there are very efficient ways of doing it and perhaps you have some samples or ideas. Basically I would like the user to be able...
3
by: MikeY | last post by:
Hi Everyone, I am working in C#, windows forms.My question is this. All my button dynamic controls properties are present and accounted for except for the"FlatStyle" properties. I can't seem to...
2
by: P2P | last post by:
Hi I am wondering if someone know of a free cross-browsers vertical scrolling script that - is cross cross-browsers - will call the scrolling content from an external html page or from a...
2
by: Rob | last post by:
I'm looking for a mod 10 script that you know to work well. I have googled and found a few different ones but I would like a 2nd opinion. If you can please link me to a mod 10 script that you have...
13
by: Avi | last post by:
Hi, Is there a UNIX C system command that will let me copy a file? I am looking for something similar to "cp" that can be called within a C program. I know of the "link" system call but this...
3
by: AMDRIT | last post by:
I am working with ObservableCollection and looking to implement sorting. I ran across code from Paul Stovell and he has: In the collection class the derives from ObservableCollection public...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.