473,587 Members | 2,473 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2300
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. design.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 "environmen t",
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*******@nowh ere.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.grayonl ine.id.au>,
Centurion <sp*******@nowh ere.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.progr ammer .
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*******@nowh ere.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 "directorie s".
#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.ne t 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.ne t 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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
3004
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 ../somewhere/picture.jpg could be read by the function and save where I specify like .../somewhere/pictureResized.jpg .....what is most important for me...
4
1709
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-- ('Fernsehturm', '20')
2
1643
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 to change their password. Then a link is mailed to their email address on file and when they click on the link, they are taken to a place to type in...
3
6816
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 figure out, if there is a way of using polymorphic way (if that is a word) of doing this particular property. A sample of my code is as follows: ...
2
2955
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 url page
2
4183
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 used/implimented I would appreciate it. Ideally I would like a vbscript over javascript so we can have it implimented on an access db as well. ...
13
1062
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 command will set a the second file as a link to the first file rather than an independent copy of the first file. (Windows has the CopyFile command...
3
1634
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 void Sort(Comparison<Tcomparrison) In the logic when initializing the collection class .... _transactions.Sort(
0
7918
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8206
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8340
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6621
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5392
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
1185
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.