Home » Language IDEs » C / C++ IDE (CDT) » fflush, stdout and cdt console
fflush, stdout and cdt console [message #53035] |
Tue, 03 December 2002 05:32  |
Eclipse User |
|
|
|
Originally posted by: the.bestel.free.fr
It seems to have a little problem with the console and CDT.
when I use printf, the program doesn't write to the standard output the
content of the buffer, but it waits that this one become full to send
all charachter strings to the console. I'm obliged to use the fflush()
function to force my program to write on the console if I want that it
works well.
On the other side, I've tried the same thing in java and it works fine
(no need to flush the output buffer).
I would like to know if this implementation is what programmers expected
or if in future release it won't be necessary to make calls to fflush...
Thanks a lot.
Nicolas ANTONIAZZI.
|
|
| |
Re: fflush, stdout and cdt console [message #53085 is a reply to message #53060] |
Tue, 03 December 2002 11:12   |
Eclipse User |
|
|
|
Originally posted by: the.bestel.free.fr
Thanks Johan :)
But the thing that I can't understant is that I use line-feed and it
doesn't work in the eclipse console (but works fine in my terminal console).
This is a short piece of code that I use :
/*********************************************************** ***/
void display_menu()
{
printf("\n\n\n************** PACKAGE TEST ************\n");
printf(" 1 - Open a package\n");
printf(" 2 - Close a package\n");
printf(" 0 - Quit\n");
}
/*********************************************************** ***/
int get_int(char *_z_message)
{
int i_choice;
char ac_choice[11];
char *z_choice;
printf("%s", _z_message);
z_choice = fgets(ac_choice, 11, stdin);
i_choice = atoi(z_choice);
return i_choice;
}
/*********************************************************** ***/
int do_choice(int _i_choice)
{
switch (_i_choice)
{
case 0:
return 0;
break;
case 1:
open_package();
break;
case 2:
close_package();
break;
default:
printf("error...\n");
break;
}
return 1;
}
/*********************************************************** ***/
int main()
{
do
{
display_menu();
}
while (do_choice(get_int("Choice : ")));
return EXIT_SUCCESS;
}
/*********************************************************** ***/
I use gcc 2.95.4 .
So, so you think that implementation of the console use in CDT will
change or I am obliged to add some fflush() in my program to test them
inside eclipse ? (I still can use my terminal console, it's not a
problem, but the IDE should be there to replace all the tools)
Thanks in advance.
Nicolas ANTONIAZZI.
Johan Walles wrote:
> This is a libc question rather than a CDT one, but I'll give it a shot
> anyway. At least the GNU implementation of printf() implicitly flushes
> stdout if you output a line-feed. So, printf("foo\n") would flush the
> buffer, but printf("foo") wouldn't.
>
> If you don't output linefeeds you'll have to use fflush().
>
> Cheers //Johan
>
> Nico wrote:
>
>> when I use printf, the program doesn't write to the standard output
>> the content of the buffer, but it waits that this one become full to
>> send all charachter strings to the console. I'm obliged to use the
>> fflush() function to force my program to write on the console if I
>> want that it works well.
>
>
|
|
|
Re: fflush, stdout and cdt console [message #53112 is a reply to message #53085] |
Tue, 03 December 2002 12:03   |
Eclipse User |
|
|
|
Its because your program is not launched on a terminal (it uses a pipe), and
buffered io will only do line buffering if it detects a real terminal (isatty)
for stdout.
You could change stdout with setvbuf() so that its unbuffered (or use the fflush() method).
Nico wrote:
> Thanks Johan :)
>
> But the thing that I can't understant is that I use line-feed and it
> doesn't work in the eclipse console (but works fine in my terminal
> console).
>
> This is a short piece of code that I use :
>
>
> /*********************************************************** ***/
>
> void display_menu()
> {
> printf("\n\n\n************** PACKAGE TEST ************\n");
> printf(" 1 - Open a package\n");
> printf(" 2 - Close a package\n");
> printf(" 0 - Quit\n");
> }
>
> /*********************************************************** ***/
>
> int get_int(char *_z_message)
> {
> int i_choice;
> char ac_choice[11];
> char *z_choice;
>
> printf("%s", _z_message);
> z_choice = fgets(ac_choice, 11, stdin);
> i_choice = atoi(z_choice);
>
> return i_choice;
> }
>
> /*********************************************************** ***/
>
> int do_choice(int _i_choice)
> {
> switch (_i_choice)
> {
> case 0:
> return 0;
> break;
> case 1:
> open_package();
> break;
> case 2:
> close_package();
> break;
> default:
> printf("error...\n");
> break;
> }
> return 1;
> }
>
> /*********************************************************** ***/
>
> int main()
> {
> do
> {
> display_menu();
> }
> while (do_choice(get_int("Choice : ")));
>
>
> return EXIT_SUCCESS;
> }
>
> /*********************************************************** ***/
>
> I use gcc 2.95.4 .
>
> So, so you think that implementation of the console use in CDT will
> change or I am obliged to add some fflush() in my program to test them
> inside eclipse ? (I still can use my terminal console, it's not a
> problem, but the IDE should be there to replace all the tools)
>
> Thanks in advance.
>
> Nicolas ANTONIAZZI.
>
> Johan Walles wrote:
>
>> This is a libc question rather than a CDT one, but I'll give it a shot
>> anyway. At least the GNU implementation of printf() implicitly
>> flushes stdout if you output a line-feed. So, printf("foo\n") would
>> flush the buffer, but printf("foo") wouldn't.
>>
>> If you don't output linefeeds you'll have to use fflush().
>>
>> Cheers //Johan
>>
>> Nico wrote:
>>
>>> when I use printf, the program doesn't write to the standard output
>>> the content of the buffer, but it waits that this one become full to
>>> send all charachter strings to the console. I'm obliged to use the
>>> fflush() function to force my program to write on the console if I
>>> want that it works well.
>>
>>
>>
>
|
|
|
Re: fflush, stdout and cdt console [message #53138 is a reply to message #53112] |
Tue, 03 December 2002 12:49   |
Eclipse User |
|
|
|
Originally posted by: the.bestel.free.fr
Ohhh, I see :)
Thank you for your help :)
Nicolas ANTONIAZZI.
Dave Inglis wrote:
> Its because your program is not launched on a terminal (it uses a pipe),
> and
> buffered io will only do line buffering if it detects a real terminal
> (isatty)
> for stdout.
>
> You could change stdout with setvbuf() so that its unbuffered (or use
> the fflush() method).
>
> Nico wrote:
>
>> Thanks Johan :)
>>
>> But the thing that I can't understant is that I use line-feed and it
>> doesn't work in the eclipse console (but works fine in my terminal
>> console).
>>
>> This is a short piece of code that I use :
>>
>>
>> /*********************************************************** ***/
>>
>> void display_menu()
>> {
>> printf("\n\n\n************** PACKAGE TEST ************\n");
>> printf(" 1 - Open a package\n");
>> printf(" 2 - Close a package\n");
>> printf(" 0 - Quit\n");
>> }
>>
>> /*********************************************************** ***/
>>
>> int get_int(char *_z_message)
>> {
>> int i_choice;
>> char ac_choice[11];
>> char *z_choice;
>>
>> printf("%s", _z_message);
>> z_choice = fgets(ac_choice, 11, stdin);
>> i_choice = atoi(z_choice);
>>
>> return i_choice;
>> }
>>
>> /*********************************************************** ***/
>>
>> int do_choice(int _i_choice)
>> {
>> switch (_i_choice)
>> {
>> case 0:
>> return 0;
>> break;
>> case 1:
>> open_package();
>> break;
>> case 2:
>> close_package();
>> break;
>> default:
>> printf("error...\n");
>> break;
>> }
>> return 1;
>> }
>>
>> /*********************************************************** ***/
>>
>> int main()
>> {
>> do
>> {
>> display_menu();
>> }
>> while (do_choice(get_int("Choice : ")));
>>
>>
>> return EXIT_SUCCESS;
>> }
>>
>> /*********************************************************** ***/
>>
>> I use gcc 2.95.4 .
>>
>> So, so you think that implementation of the console use in CDT will
>> change or I am obliged to add some fflush() in my program to test them
>> inside eclipse ? (I still can use my terminal console, it's not a
>> problem, but the IDE should be there to replace all the tools)
>>
>> Thanks in advance.
>>
>> Nicolas ANTONIAZZI.
>>
>> Johan Walles wrote:
>>
>>> This is a libc question rather than a CDT one, but I'll give it a
>>> shot anyway. At least the GNU implementation of printf() implicitly
>>> flushes stdout if you output a line-feed. So, printf("foo\n") would
>>> flush the buffer, but printf("foo") wouldn't.
>>>
>>> If you don't output linefeeds you'll have to use fflush().
>>>
>>> Cheers //Johan
>>>
>>> Nico wrote:
>>>
>>>> when I use printf, the program doesn't write to the standard output
>>>> the content of the buffer, but it waits that this one become full to
>>>> send all charachter strings to the console. I'm obliged to use the
>>>> fflush() function to force my program to write on the console if I
>>>> want that it works well.
>>>
>>>
>>>
>>>
>>
>
|
|
|
Re: fflush, stdout and cdt console [message #53164 is a reply to message #53112] |
Wed, 04 December 2002 03:13   |
Eclipse User |
|
|
|
Originally posted by: johan.nosp.m.appeal.se
Since this makes programs run from within Eclipse behave differently
from when they are run from outside of Eclipse, this is a problem.
Maybe not a *huge* problem, but still a problem.
Dave, do you know if glibc could somehow be tricked into thinking that
Eclipse's pipe really isatty()?
Cheers //Johan
Dave Inglis wrote:
> Its because your program is not launched on a terminal (it uses a pipe),
> and
> buffered io will only do line buffering if it detects a real terminal
> (isatty)
> for stdout.
>
> You could change stdout with setvbuf() so that its unbuffered (or use
> the fflush() method).
>
> Nico wrote:
>
>> Thanks Johan :)
>>
>> But the thing that I can't understant is that I use line-feed and it
>> doesn't work in the eclipse console (but works fine in my terminal
>> console).
>>
>> This is a short piece of code that I use :
>>
>>
>> /*********************************************************** ***/
>>
>> void display_menu()
>> {
>> printf("\n\n\n************** PACKAGE TEST ************\n");
>> printf(" 1 - Open a package\n");
>> printf(" 2 - Close a package\n");
>> printf(" 0 - Quit\n");
>> }
>>
>> /*********************************************************** ***/
>>
>> int get_int(char *_z_message)
>> {
>> int i_choice;
>> char ac_choice[11];
>> char *z_choice;
>>
>> printf("%s", _z_message);
>> z_choice = fgets(ac_choice, 11, stdin);
>> i_choice = atoi(z_choice);
>>
>> return i_choice;
>> }
>>
>> /*********************************************************** ***/
>>
>> int do_choice(int _i_choice)
>> {
>> switch (_i_choice)
>> {
>> case 0:
>> return 0;
>> break;
>> case 1:
>> open_package();
>> break;
>> case 2:
>> close_package();
>> break;
>> default:
>> printf("error...\n");
>> break;
>> }
>> return 1;
>> }
>>
>> /*********************************************************** ***/
>>
>> int main()
>> {
>> do
>> {
>> display_menu();
>> }
>> while (do_choice(get_int("Choice : ")));
>>
>>
>> return EXIT_SUCCESS;
>> }
>>
>> /*********************************************************** ***/
>>
>> I use gcc 2.95.4 .
>>
>> So, so you think that implementation of the console use in CDT will
>> change or I am obliged to add some fflush() in my program to test them
>> inside eclipse ? (I still can use my terminal console, it's not a
>> problem, but the IDE should be there to replace all the tools)
>>
>> Thanks in advance.
>>
>> Nicolas ANTONIAZZI.
>>
>> Johan Walles wrote:
>>
>>> This is a libc question rather than a CDT one, but I'll give it a
>>> shot anyway. At least the GNU implementation of printf() implicitly
>>> flushes stdout if you output a line-feed. So, printf("foo\n") would
>>> flush the buffer, but printf("foo") wouldn't.
>>>
>>> If you don't output linefeeds you'll have to use fflush().
>>>
>>> Cheers //Johan
>>>
>>> Nico wrote:
>>>
>>>> when I use printf, the program doesn't write to the standard output
>>>> the content of the buffer, but it waits that this one become full to
>>>> send all charachter strings to the console. I'm obliged to use the
>>>> fflush() function to force my program to write on the console if I
>>>> want that it works well.
>>>
>>>
>>>
>>>
>>
>
|
|
|
Re: fflush, stdout and cdt console [message #53189 is a reply to message #53164] |
Wed, 04 December 2002 10:21   |
Eclipse User |
|
|
|
Its possibly to make this work correctly since we do have control over the
low-level launching of the process through a spawner class (instead of using
Runtime.exec()). It just a matter of making the changes required for each
platform wrt pty handling and all that fun stuff.
Johan Walles wrote:
> Since this makes programs run from within Eclipse behave differently
> from when they are run from outside of Eclipse, this is a problem. Maybe
> not a *huge* problem, but still a problem.
>
> Dave, do you know if glibc could somehow be tricked into thinking that
> Eclipse's pipe really isatty()?
>
> Cheers //Johan
>
> Dave Inglis wrote:
>
>> Its because your program is not launched on a terminal (it uses a
>> pipe), and
>> buffered io will only do line buffering if it detects a real terminal
>> (isatty)
>> for stdout.
>>
>> You could change stdout with setvbuf() so that its unbuffered (or use
>> the fflush() method).
>>
>> Nico wrote:
>>
>>> Thanks Johan :)
>>>
>>> But the thing that I can't understant is that I use line-feed and it
>>> doesn't work in the eclipse console (but works fine in my terminal
>>> console).
>>>
>>> This is a short piece of code that I use :
>>>
>>>
>>> /*********************************************************** ***/
>>>
>>> void display_menu()
>>> {
>>> printf("\n\n\n************** PACKAGE TEST ************\n");
>>> printf(" 1 - Open a package\n");
>>> printf(" 2 - Close a package\n");
>>> printf(" 0 - Quit\n");
>>> }
>>>
>>> /*********************************************************** ***/
>>>
>>> int get_int(char *_z_message)
>>> {
>>> int i_choice;
>>> char ac_choice[11];
>>> char *z_choice;
>>>
>>> printf("%s", _z_message);
>>> z_choice = fgets(ac_choice, 11, stdin);
>>> i_choice = atoi(z_choice);
>>>
>>> return i_choice;
>>> }
>>>
>>> /*********************************************************** ***/
>>>
>>> int do_choice(int _i_choice)
>>> {
>>> switch (_i_choice)
>>> {
>>> case 0:
>>> return 0;
>>> break;
>>> case 1:
>>> open_package();
>>> break;
>>> case 2:
>>> close_package();
>>> break;
>>> default:
>>> printf("error...\n");
>>> break;
>>> }
>>> return 1;
>>> }
>>>
>>> /*********************************************************** ***/
>>>
>>> int main()
>>> {
>>> do
>>> {
>>> display_menu();
>>> }
>>> while (do_choice(get_int("Choice : ")));
>>>
>>>
>>> return EXIT_SUCCESS;
>>> }
>>>
>>> /*********************************************************** ***/
>>>
>>> I use gcc 2.95.4 .
>>>
>>> So, so you think that implementation of the console use in CDT will
>>> change or I am obliged to add some fflush() in my program to test
>>> them inside eclipse ? (I still can use my terminal console, it's not
>>> a problem, but the IDE should be there to replace all the tools)
>>>
>>> Thanks in advance.
>>>
>>> Nicolas ANTONIAZZI.
>>>
>>> Johan Walles wrote:
>>>
>>>> This is a libc question rather than a CDT one, but I'll give it a
>>>> shot anyway. At least the GNU implementation of printf() implicitly
>>>> flushes stdout if you output a line-feed. So, printf("foo\n") would
>>>> flush the buffer, but printf("foo") wouldn't.
>>>>
>>>> If you don't output linefeeds you'll have to use fflush().
>>>>
>>>> Cheers //Johan
>>>>
>>>> Nico wrote:
>>>>
>>>>> when I use printf, the program doesn't write to the standard output
>>>>> the content of the buffer, but it waits that this one become full
>>>>> to send all charachter strings to the console. I'm obliged to use
>>>>> the fflush() function to force my program to write on the console
>>>>> if I want that it works well.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>
>>
>
|
|
|
Re: fflush, stdout and cdt console [message #53215 is a reply to message #53189] |
Wed, 04 December 2002 11:00  |
Eclipse User |
|
|
|
Originally posted by: johan.nosp.m.appeal.se
Posted bug 27663: http://bugs.eclipse.org/bugs/show_bug.cgi?id=27663
Cheers //Johan
Dave Inglis wrote:
> Its possibly to make this work correctly since we do have control over the
> low-level launching of the process through a spawner class (instead of
> using
> Runtime.exec()). It just a matter of making the changes required for each
> platform wrt pty handling and all that fun stuff.
>
> Johan Walles wrote:
>
>> Since this makes programs run from within Eclipse behave differently
>> from when they are run from outside of Eclipse, this is a problem.
>> Maybe not a *huge* problem, but still a problem.
>>
>> Dave, do you know if glibc could somehow be tricked into thinking that
>> Eclipse's pipe really isatty()?
>>
>> Cheers //Johan
>>
>> Dave Inglis wrote:
>>
>>> Its because your program is not launched on a terminal (it uses a
>>> pipe), and
>>> buffered io will only do line buffering if it detects a real terminal
>>> (isatty)
>>> for stdout.
>>>
>>> You could change stdout with setvbuf() so that its unbuffered (or use
>>> the fflush() method).
|
|
|
Goto Forum:
Current Time: Sun Apr 27 10:02:21 EDT 2025
Powered by FUDForum. Page generated in 0.03778 seconds
|