Visit Our UNIX and Linux User Community


Show progress in console application


 
Thread Tools Search this Thread
Top Forums Programming Show progress in console application
# 1  
Old 05-10-2010
Show progress in console application

Hi all
I have a program in C++ that I compiled on Ubuntu 9.0 and Centos 5, after I got it running on Windows. In this program, I show progress of a process using the following construct:

Code:
i = 0;
quantum = floor(total_iterations, 100);
perc = 0;
do
{
  remain = fmod(i, quantum);
  if(remain == 0)
  {
     printf("%d percent complete\r", perc);
     perc++;
  }
  i++;
}while(condition);

The progress shows correctly on Windows, i.e., I see "1 percent complete", then "2 percent complete" and so on. However, when I run the program on *nix, the progress does not show. All I see is the final "100 percent compelte"
I can't figure out why this would be the case. Any clue?

Last edited by msaqib; 05-10-2010 at 08:01 AM.. Reason: use code tags please, ty
# 2  
Old 05-10-2010
First, that code is C, not C++.
Second, output on most UNIX terminals is line buffered, which means that a line won't be printed until it's ended ith a newline. You can use either fflush after each line or setvbuf on stdout to force output.
# 3  
Old 05-10-2010
Awesome! Thanks pludi. I think that is what would work. I'll try it out as soon as my current simulation thread stops.
# 4  
Old 05-10-2010
You could also try printing to stderr, which is unbuffered by tradition.

Previous Thread | Next Thread
Test Your Knowledge in Computers #445
Difficulty: Easy
Scientific Linux has been loaded onto systems at the International Space Station.
True or False?

10 More Discussions You Might Find Interesting

1. IP Networking

How to show Cisco Router Running Configuration in Third Party Application

Hey everyone, I have a few question. 1. Is it possible to display cisco 'show run' output command to the application ?? 2. And is there any ways to log in to the router instead of using telnet from telnet application??? Thanks in advance (0 Replies)
Discussion started by: franzramadhan
0 Replies

2. UNIX for Advanced & Expert Users

Needs help in launching a console application with the help of daemon process

Hi All, I am facing problem in launching a application with the help of a daemon process. Actually the application is based on command line that reads various commands for controlling the application from the console and accordingly executes those commands. The application always interact with... (3 Replies)
Discussion started by: gopallinux
3 Replies

3. Shell Programming and Scripting

Just want to show wget progress bar

I have been developing a download manager bash script recently using wget. while downloading a file, the user interface is something like downloading: DSCF0599.JPG ... --09:30:42-- http://xxx.xxx/DSCF0599.JPG => `/home/rastacre/Downloads/DSCF0599.JPG' Resolving xxx.xxx...... (2 Replies)
Discussion started by: anid
2 Replies

4. UNIX for Dummies Questions & Answers

Windows to Linux remote console using VNC brings up blank console screen with only mouse pointer

:confused:Hi This was installed on the Linux box a few weeks back by a guy that no longer works for us. All worked fine until last week. Now when we connect its just a blank screen with no icons. I get a whole bunch of errors when starting the service too: Tue Feb 23 14:29:45 2010 ... (1 Reply)
Discussion started by: wbdevilliers
1 Replies

5. Shell Programming and Scripting

Show status of progress?

So, What is the best method, if even possible, to display a percentage or a status or progress of a certain command? For example I am forcing a block copy of a an OS image from one machine to another via a shell script and would like for it to display a progress or status so I know if it is... (3 Replies)
Discussion started by: tlarkin
3 Replies

6. Programming

What is the difference between console-based and xwindow-based application?

Hi everyone, What is the difference between console-based and Xwindow-based application? Can I say the application working well in Xwindows can work in console? Can I say the application working well in console cann't work in Xwindow perhaps. Eg, ncurses is console-based and Imlib2 is... (4 Replies)
Discussion started by: liuyan03
4 Replies

7. Shell Programming and Scripting

console redirect of progress bar

I'm trying to write a python wrapper around wget to show the progress bar on a gui application. Wget gives you a progress bar on command line, but how would I pipe that to some "tty" that's really just a variable I read, or am I going about it all wrong? When I try to just redirect the output to a... (1 Reply)
Discussion started by: unclecameron
1 Replies

8. Linux

Why our application can't show the BarCode Font?

please (1 Reply)
Discussion started by: gongweixiang
1 Replies

9. Debian

Why our application can't show the BarCode Font?

We use the debian 4.0 Linux with the wine 1.0. When we run our application on this platform, there is a problem: The Barcode can't be displayed correctly, but occurs some Garbled. The font we use is “Carolinabar-B39-25F2”. But when we install the wine-0.9.25 instead of wine-1.0, the barcode can... (1 Reply)
Discussion started by: gongweixiang
1 Replies

10. Shell Programming and Scripting

How to show progress bar for a running process

Hi, I have 2 shell scripts ,one for taking hot backup of oracle Database while other is for progress bar. But I don't have an idea hoe should I incorporate the shell script of progress bar in my hot backup code . Please help. My shell script for hot backup is as below: ... (0 Replies)
Discussion started by: dwiravi
0 Replies

Featured Tech Videos