Author Topic: console app in windows xp doesn't run properly  (Read 7477 times)

Offline itbhp

  • Single posting newcomer
  • *
  • Posts: 6
console app in windows xp doesn't run properly
« on: October 09, 2008, 06:38:52 pm »
I have written a simple console app that writes the sum of even elements of fibonacci sequence lesser than an upper bound.

Code
#include <iostream>
#include <vector>

using namespace std;

vector<int> lista_fibonacci(int upper_bound)
{
    vector<int> lista;
    lista.push_back(1);
    lista.push_back(1);
    int i=1;
    while (lista[i-1]+lista[i] < upper_bound)
    {
        lista.push_back(lista[i-1]+lista[i]);
        i++;
    }
    return lista;
}

int Sum_even(vector<int> lista)
{
    int sum = 0;
    for (int i=0; i<lista.size(); i++) if((lista[i]%2)==0) sum+=lista[i];
    return sum;
}

void stampa(const vector<int> lista)
{
 for(int i=0; i<lista.size();i++)
  cout << lista[i] << " ";
 cout << endl;
}

int main()
{
    vector<int> lista_fib;
    int upper_bound=40000;
    lista_fib=lista_fibonacci(upper_bound);
    cout<<endl<<"Valori della serie di Fibonacci minori di "<<upper_bound<<endl;
    stampa(lista_fib);
    cout<<endl<< "La somma dei valori pari della serie di Fibonacci minori di "<<upper_bound<<" e': " << Sum_even(lista_fib)<<endl;
    return 0;
}


I didn't start a project in CodeBlocks but I created only a simple cpp file. It builds right but when I try to run it in CodeBlocks, it appears a command window with these lines:

Process returned 0 <0x0> execution time : 0.109 s
Press any key to continue.

Searching the forum I discovered that these lines are related with a file "cb_console_runner.exe" that CodeBlocks calls when it runs console app.

The problem is that launching program from command line window after compiling works fine but running it in codeblocks doesn't, that is: it doesn't show my program output but only those lines.

How can I fix this?

Thanks for help,
 Paolo

P.S.: I use Windows Xp Home Service Pack 3 and CodeBlocks 8.02 (codeblocks-8.02mingw-setup.exe).
« Last Edit: October 14, 2008, 01:26:28 pm by itbhp »
"Anyone who has never made a mistake has never tried anything new."
A.E.

Offline odubtaig

  • Single posting newcomer
  • *
  • Posts: 9
Re: console app in windows xp doesn't run properly
« Reply #1 on: October 09, 2008, 07:22:55 pm »
Did you specifically create a console application project? It doesn't read like you did. I've not had this problem with the same release.

Offline itbhp

  • Single posting newcomer
  • *
  • Posts: 6
Re: console app in windows xp doesn't run properly
« Reply #2 on: October 09, 2008, 08:30:33 pm »
Quote
I didn't start a project in CodeBlocks but I created only a simple cpp file.

By the way even starting a console application project the problem remains.

Probably I wasn't clear: the error is that by clicking the "Run" button in Codeblocks  it appears a command window with these lines:

Process returned 0 <0x0> execution time : 0.109 s
Press any key to continue.

even if the file.exe exists and I get the right output in a different command window I opened.

"Anyone who has never made a mistake has never tried anything new."
A.E.

Offline Jenna

  • Administrator
  • Lives here!
  • *****
  • Posts: 7256
Re: console app in windows xp doesn't run properly
« Reply #3 on: October 09, 2008, 08:53:54 pm »
Your file works fine for me.


Pleae turn on full commandline logging :"Settings -> Compiler and debugger... -> Global compiler settings -> Other settings(rightmost tab)" "Compiler logging" to "Full commandline" .

And the run it again and post the lines from the "Build log".

Offline itbhp

  • Single posting newcomer
  • *
  • Posts: 6
Re: console app in windows xp doesn't run properly
« Reply #4 on: October 09, 2008, 09:15:27 pm »
Nothing has changed.  :(

This is the build log.

Code
 mingw32-g++.exe -march=pentium-m -Os -W -g    -c "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp" -o "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.o"
C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp: In function `int Sum_even(std::vector<int, std::allocator<int> >)':
C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp:24: warning: comparison between signed and unsigned integer expressions
C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp: In function `void stampa(std::vector<int, std::allocator<int> >)':
C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.cpp:30: warning: comparison between signed and unsigned integer expressions
mingw32-g++.exe  -o "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.exe" "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.o"   
Process terminated with status 0 (0 minutes, 2 seconds)
0 errors, 2 warnings
 
Checking for existence: C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.exe
Executing: C:\Programmi\CodeBlocks/cb_console_runner.exe "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.exe" (in C:\Documents and Settings\paolo\Documenti\My_sources\c++)
Process terminated with status 0 (0 minutes, 11 seconds)
 
"Anyone who has never made a mistake has never tried anything new."
A.E.

Offline rhf

  • Multiple posting newcomer
  • *
  • Posts: 123
Re: console app in windows xp doesn't run properly
« Reply #5 on: October 09, 2008, 09:32:33 pm »
itbhp,
It looks like it is running.  Are you sure the output window is not closing?
You might try: Project->Properties->Build targets
        and under Type: Console application:  check 'Pause when execution ends'.

Offline itbhp

  • Single posting newcomer
  • *
  • Posts: 6
Re: console app in windows xp doesn't run properly
« Reply #6 on: October 09, 2008, 10:00:09 pm »
rhf said
Quote
You might try: Project->Properties->Build targets
        and under Type: Console application:  check 'Pause when execution ends'.

It was already checked.

I tried also to launch the exact command that codeblocks launches when I click the "Run" button, following these steps:

1. Launch Command prompt
2. change directory into "C:\Programmi\CodeBlocks"
3. C:\Programmi\CodeBlocks> cb_console_runner.exe "C:\Documents and Settings\paolo\Documenti\My_sources\c++\sum_even_values_fibonacci_seq.exe"

The output was the same:

Process returned 0 <0x0> execution time : 0.109 s
Press any key to continue.

Maybe this cb_console_runner doesn't work as it should.
« Last Edit: October 10, 2008, 05:41:46 pm by itbhp »
"Anyone who has never made a mistake has never tried anything new."
A.E.

Offline itbhp

  • Single posting newcomer
  • *
  • Posts: 6
Re: console app in windows xp doesn't run properly
« Reply #7 on: October 10, 2008, 11:19:50 am »
I tried to uncheck "Project->Properties->Build targets and under Type: Console application:   'Pause when execution ends'. "

Now project works fine and to see the output of the program I have just to add these lines to my code:

Code
system("PAUSE"); // or cin.get();


By the way simple file that doesn't belong to any project still doesn't run properly.

Thanks for help.
« Last Edit: October 10, 2008, 12:04:37 pm by itbhp »
"Anyone who has never made a mistake has never tried anything new."
A.E.

Offline itbhp

  • Single posting newcomer
  • *
  • Posts: 6
Re: console app in windows xp doesn't run properly
« Reply #8 on: October 10, 2008, 12:04:01 pm »
News:

After I renamed C:\Programmi\Codeblocks\cb_console_runner.exe in C:\Programmi\Codeblocks\cb_console_runner-old.exe, now also simple cpp file that doesn't belong to any project runs properly.

 :o



« Last Edit: October 10, 2008, 12:08:38 pm by itbhp »
"Anyone who has never made a mistake has never tried anything new."
A.E.