Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Read output from system( ).

Reply
Thread Tools

Read output from system( ).

 
 
Kevin Easton
Guest
Posts: n/a
 
      10-06-2003
Floyd Davidson <(E-Mail Removed)> wrote:
> Richard Heathfield <(E-Mail Removed)> wrote:
>>Floyd Davidson wrote:
>>
>><snip>
>>
>>> C.l.c is for C lawyering, not C programming.

>>
>>If that has become true, it's a sad day for Usenet. I prefer to think of clc
>>as being for programming in C, rather than programming for a platform. C
>>lawyering really belongs in csc, IMHO.

>
> C.s.c is for C legislating.
>
> Then the lawyers get it, and that's here.
>
> Incidentally, I don't see that separation as a sad day. There
> really is a distinct separation in the three areas. (I don't
> get a negative connotation from "lawyering" either, and that may
> be the only difference in what we mean.)


I think Richard might have been referring to the "and not C programming"
bit. The key is realising that comp.lang.c is for C programming - but
not for programming-to-APIs-that-happen-to-have-a-C-binding.

By the way, I don't think it's offtopic at all to ask "can I read the
standard output of a program I start with system()" - it's just that the
answer is "no", or more verbosely, "no, unless you can rely on running
on a particular subset of C-supporting systems, so you might want to ask
in a newsgroup dedicated to programming on your particular system, to
see if it's one of them".

- Kevin.

 
Reply With Quote
 
 
 
 
Floyd Davidson
Guest
Posts: n/a
 
      10-06-2003
Kevin Easton <(E-Mail Removed)> wrote:
>Floyd Davidson <(E-Mail Removed)> wrote:
>> Richard Heathfield <(E-Mail Removed)> wrote:
>>>Floyd Davidson wrote:
>>>
>>><snip>
>>>
>>>> C.l.c is for C lawyering, not C programming.
>>>
>>>If that has become true, it's a sad day for Usenet. I prefer to think of clc
>>>as being for programming in C, rather than programming for a platform. C
>>>lawyering really belongs in csc, IMHO.

>>
>> C.s.c is for C legislating.
>>
>> Then the lawyers get it, and that's here.


....

>By the way, I don't think it's offtopic at all to ask "can I read the
>standard output of a program I start with system()" - it's just that the
>answer is "no", or more verbosely, "no, unless you can rely on running
>on a particular subset of C-supporting systems, so you might want to ask
>in a newsgroup dedicated to programming on your particular system, to
>see if it's one of them".


See what I mean about C lawyering! A great example, thank you.

Many programs "rely on running on a particular subset of
C-supporting systems". We aren't going to say "no, unless"
every time anyone includes stdio.h and uses any function
declared therein. Your point is not significant, and your
initial "no" based on it is incorrect.

We agree on everything else, hence, the correct response is
"Yes, but ..."

--
Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      10-06-2003
Kevin Easton wrote:

> Floyd Davidson <(E-Mail Removed)> wrote:
>> Richard Heathfield <(E-Mail Removed)> wrote:
>>>Floyd Davidson wrote:
>>>
>>><snip>
>>>
>>>> C.l.c is for C lawyering, not C programming.
>>>
>>>If that has become true, it's a sad day for Usenet. I prefer to think of
>>>clc as being for programming in C, rather than programming for a
>>>platform. C lawyering really belongs in csc, IMHO.

>>
>> C.s.c is for C legislating.
>>
>> Then the lawyers get it, and that's here.
>>
>> Incidentally, I don't see that separation as a sad day. There
>> really is a distinct separation in the three areas. (I don't
>> get a negative connotation from "lawyering" either, and that may
>> be the only difference in what we mean.)

>
> I think Richard might have been referring to the "and not C programming"
> bit.


Indeed he was (and I should know).

> The key is realising that comp.lang.c is for C programming - but
> not for programming-to-APIs-that-happen-to-have-a-C-binding.


Precisely. We have no more questions for this witness, m'lud.

<snip>

--
Richard Heathfield : (E-Mail Removed)
"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
 
Reply With Quote
 
Micah Cowan
Guest
Posts: n/a
 
      10-06-2003
Floyd Davidson <(E-Mail Removed)> writes:

> CBFalconer <(E-Mail Removed)> wrote:
> >Floyd Davidson wrote:
> >>

> >... snip ...
> >>
> >> Regardless, there is a Standard C answer, which just doesn't
> >> happen to be as nice as the unix popen() method. The command
> >> given to the system() function can redirect stdout to a file.
> >> The program then simply reads the file.

> >
> >That is not a standard C answer. C says nothing about what
> >system() actually does, and such things as executing programs and
> >redirection are system and implementation dependant. Your
> >solution can be expected to work on unix/linux/msdos, but probably
> >not under OS360 or MPE on the HP3000.

>
> So? That hardly keeps it from being a Standard C answer.


Doesn't it? If the answer has nothing to do with Standard C, it
is not a Standard C answer.

> After all, the standard doesn't require there be anything
> connected to stdout, and on some platforms using printf()
> results in a no-op. Same with system() in this case.
>
> The point is, the C code does not violate the C Standard.


That has nothing to do with whether your answer is a "Standard C
answer". In particular, your assertion that "the command given to
the system() function can redirect stdout to a file" may or may
not be true: the Standard has nothing to say about whether this
is actually possible, so it is assuredly not a Standard C answer.

-Micah
 
Reply With Quote
 
Kevin Easton
Guest
Posts: n/a
 
      10-06-2003
Floyd Davidson <(E-Mail Removed)> wrote:
> Kevin Easton <(E-Mail Removed)> wrote:
>>Floyd Davidson <(E-Mail Removed)> wrote:
>>> Richard Heathfield <(E-Mail Removed)> wrote:
>>>>Floyd Davidson wrote:
>>>>
>>>><snip>
>>>>
>>>>> C.l.c is for C lawyering, not C programming.
>>>>
>>>>If that has become true, it's a sad day for Usenet. I prefer to think of clc
>>>>as being for programming in C, rather than programming for a platform. C
>>>>lawyering really belongs in csc, IMHO.
>>>
>>> C.s.c is for C legislating.
>>>
>>> Then the lawyers get it, and that's here.

>
> ...
>
>>By the way, I don't think it's offtopic at all to ask "can I read the
>>standard output of a program I start with system()" - it's just that the
>>answer is "no", or more verbosely, "no, unless you can rely on running
>>on a particular subset of C-supporting systems, so you might want to ask
>>in a newsgroup dedicated to programming on your particular system, to
>>see if it's one of them".

>
> See what I mean about C lawyering! A great example, thank you.
>
> Many programs "rely on running on a particular subset of
> C-supporting systems". We aren't going to say "no, unless"
> every time anyone includes stdio.h and uses any function
> declared therein. Your point is not significant, and your
> initial "no" based on it is incorrect.
>
> We agree on everything else, hence, the correct response is
> "Yes, but ..."


In that case the answer to *every* question is "Yes, but.." and thus
you could ask everything from "How do I turn off my combine harvester"
to "Why don't my ailerons deflect far enough."

"I'm starting Excel from system(). What is the correct string to use to
make it use European dates?" Now, is that a question about C, just
because it involves a C function? Or is it an Excel question? The same
applies to "What is the correct string to use in system() to make it
send the standard output of a program to a file?" - it's a question
about your shell, not about C.

Being within earshot of C does not make something C.

- Kevin.

 
Reply With Quote
 
Floyd Davidson
Guest
Posts: n/a
 
      10-06-2003
Kevin Easton <(E-Mail Removed)> wrote:
>
>In that case the answer to *every* question is "Yes, but.." and thus
>you could ask everything from "How do I turn off my combine harvester"
>to "Why don't my ailerons deflect far enough."
>
>"I'm starting Excel from system(). What is the correct string to use to
>make it use European dates?" Now, is that a question about C, just
>because it involves a C function? Or is it an Excel question? The same
>applies to "What is the correct string to use in system() to make it
>send the standard output of a program to a file?" - it's a question
>about your shell, not about C.
>
>Being within earshot of C does not make something C.
>
> - Kevin.


Did you have any comments that related to either C programming
or to C lawyering?

--
Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
Ukpeagvik (Barrow, Alaska) (E-Mail Removed)
 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      10-06-2003
In <blojih$mes$(E-Mail Removed)> Richard Heathfield <(E-Mail Removed)> writes:

>SR wrote:
>
>> I need to read the output from a system( ) function within a C program.
>> The function however only returns the exit status.
>> How can I read what system( ) sends to stdout ?

>
>system("foo > filename.txt");
>fp = fopen("filename.txt", r");


Where does the standard say that, if the fopen call succeeds, the
stream contains the output of the command executed by system()?

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
 
Reply With Quote
 
Dan Pop
Guest
Posts: n/a
 
      10-06-2003
In <(E-Mail Removed)> Floyd Davidson <(E-Mail Removed)> writes:

>The point is, the C code does not violate the C Standard.


Nope, the point is, the C standard doesn't say the code will have the
effect intended by the OP. From the point of view of the C standard,
system("foo >out.txt") and popen("foo", "r") are equally implementation
specific solutions (it is not a standard violation to call a function
called popen), that may or may not work on a conforming C implementation.

The only difference is that one may fail at run time and the other
in translation phase 8.

Dan
--
Dan Pop
DESY Zeuthen, RZ group
Email: (E-Mail Removed)
 
Reply With Quote
 
Richard Heathfield
Guest
Posts: n/a
 
      10-07-2003
Dan Pop wrote:
> In <blojih$mes$(E-Mail Removed)> Richard Heathfield writes:
>>SR wrote:
>>> I need to read the output from a system( ) function within a C program.
>>> The function however only returns the exit status.
>>> How can I read what system( ) sends to stdout ?

>>
>>system("foo > filename.txt");
>>fp = fopen("filename.txt", r");

>
> Where does the standard say that, if the fopen call succeeds, the
> stream contains the output of the command executed by system()?


For a moment I forgot where I was, and I accidentally gave a pragmatic reply
that would actually help the OP out of his current difficulty. I do
apologise - to you, to the OP, and indeed to the whole group. I'll try not
to make the same mistake again.

--
Richard Heathfield : (E-Mail Removed)
"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
 
Reply With Quote
 
Mike Wahler
Guest
Posts: n/a
 
      10-07-2003
"Richard Heathfield" <(E-Mail Removed)> wrote in message
news:bltd0e$grl$(E-Mail Removed)...
> Dan Pop wrote:
> > In <blojih$mes$(E-Mail Removed)> Richard Heathfield writes:
> >>SR wrote:
> >>> I need to read the output from a system( ) function within a C

program.
> >>> The function however only returns the exit status.
> >>> How can I read what system( ) sends to stdout ?
> >>
> >>system("foo > filename.txt");
> >>fp = fopen("filename.txt", r");

> >
> > Where does the standard say that, if the fopen call succeeds, the
> > stream contains the output of the command executed by system()?

>
> For a moment I forgot where I was, and I accidentally gave a pragmatic

reply
> that would actually help the OP out of his current difficulty. I do
> apologise - to you, to the OP, and indeed to the whole group. I'll try not
> to make the same mistake again.


Despite my 'reputation' as an officer of the 'topic police',
I'd like to say that your reply imo would be perfectly
acceptable were it prefaced, e.g.

"Many operating systems have the facility to 'redirect'
the output of a command to a file. *For example*, some
OS's, e.g. MSDOS/Windows/Unix use the '>' character".

Then your example code, perhaps followed by "check your
OS documentation to be sure."

So imo you simply "started talking before your mouth was
completely open". And of course, given your history
here, I certainly forgive you.

Oh, and (my desperate attempt to return to topicality):
you forgot the opening quote on 'fopen()'s "r" argument.
Now go write a 'for' loop on the blackboard.

I suppose someone will flame me for saying all this, but it's
getting chilly outside, so...

-Mike


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange problem - page output contains output from another request Paul ASP .Net 1 04-10-2007 03:41 PM
parse output screen ok but cant get desired output new file! chuck amadi Python 1 06-23-2004 02:16 PM
Sony Precision Cinema Progressive Output vs Component 480p Output Otto Pylot DVD Video 1 04-18-2004 09:49 PM
Is Fuji S3000 3.2m/pixel output, or 6 m/pixel interpolated output? Peter H Digital Photography 43 12-04-2003 02:35 PM
Output / Debug window output bug? John Bentley ASP .Net 0 09-10-2003 07:38 AM



Advertisments