Recent

Author Topic: [SOLVED] Console program opens new console on Windows?  (Read 6999 times)

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
[SOLVED] Console program opens new console on Windows?
« on: May 07, 2012, 01:00:12 pm »
Hi all,

Windows x64 Vista SP2
Lazarus i386 SVN (r37168), FPC 2.6.1

I must be doing something wrong, but can't figure out what.
Am trying to test a console program.
Have disabled Win32 gui application (-WG) in project options/linking.
Have added an {$apptype console} at the beginning.

However, when I start a command window, then run the executable, it flashes a new windows briefly and returns to the prompt instead of running in the first window.

What am I doing wrong? It must be something very obvious and stupid...

Thanks
« Last Edit: May 08, 2012, 01:11:22 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Console program opens new console on Windows?
« Reply #1 on: May 08, 2012, 08:41:28 am »
Bump. Think I should raise a bug report for this? Most of the time, it turns out to be a PICNIC/PEBKAC problem, so I'd appreciate somebody taking a look at it.

Thanks.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Console program opens new console on Windows?
« Reply #2 on: May 08, 2012, 09:06:09 am »
Screen dump on xp 32. Project compiled without modifying anything.
Code: [Select]
C:\Documents and Settings\Ludo\Mes documents\Lazarus Projects\test\console>cancelupdatescrash.exe
starting
Added records. Now 17 records.
Deleted records. Now 12 records.
Record 12 is wrong; it has ID: 12
Record 12 is wrong; it has name: TestName12
An unhandled exception occurred at $0040288B:
EAccessViolation: Access violation
An unhandled exception occurred at $00410E31:
EInOutError: Unknown Run-Time error : 131
  $00410E31
  $0041172C
  $00411BD2
  $00411C62
  $00428037
  $0040AC34
  $0040AEA9


C:\Documents and Settings\Ludo\Mes documents\Lazarus Projects\test\console>
Nothing wrong there (seen the filename I guess the EAccessViolation is expected). Are you sure you don't have an old exe lying around that is started from the console?

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Console program opens new console on Windows?
« Reply #3 on: May 08, 2012, 09:26:18 am »
Very weird. Yes the access violation is expected.

Vista x64, extracted zip into a clean directory.
Using fpc 2.6.1 x86:
Code: [Select]
d:\Cop\t>fpc cancelupdatescrash.lpr
Free Pascal Compiler version 2.6.1 [2012/05/08] for i386
...
d:\Cop\t>cancelupdatescrash.exe
...<flashing new console window>...
d:\Cop\t>

FPC trunk, i386 (after running delp ., del *.exe):
Code: [Select]
d:\Cop\t>fpcdev cancelupdatescrash.lpr
Free Pascal Compiler version 2.7.1 [2012/05/08] for i386
...
d:\Cop\t>cancelupdatescrash.exe
...<a fairly long period of nothing, then a flashing new console window>...
d:\Cop\t>

Wait a minute... I compiled this in a regular cmd shell under Vista (UAC is turned off)...
If I run the exe in an admin shell (ehrm Administrative Command Prompt), it works (i.e. shows the output).
If I run the exe in the normal shell, I get a popup (=> admin command window?)
Perhaps Windows for some reason thinks I need to have elevated privileges for this code?!?

Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Console program opens new console on Windows?
« Reply #4 on: May 08, 2012, 10:52:58 am »
Can't reproduce it on win7 64,  with or without UAC turned off.
There is no manifest file for cancelupdatescrash?

KpjComp

  • Hero Member
  • *****
  • Posts: 680
Re: Console program opens new console on Windows?
« Reply #5 on: May 08, 2012, 11:54:40 am »
Works here fine too.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 10084
  • FPC developer.
Re: Console program opens new console on Windows?
« Reply #6 on: May 08, 2012, 12:36:40 pm »
IIRC anything with "patch", "update", "install and "setup" etc is automatically UACed. There are a few more keywords that trigger this.

With FPC we had trouble with patch and ginstall for a while, till we added manifest files for them.

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: Console program opens new console on Windows?
« Reply #7 on: May 08, 2012, 01:04:00 pm »
Fired my Vista VM up and can indeed reproduce the problem. As Marco said, change the name of the executable and it will run normally.

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: Console program opens new console on Windows?
« Reply #8 on: May 08, 2012, 01:10:30 pm »
Thanks guys. Verified; renaming cancelupdatescrash.exe to bla.exe lets me run the program without elevation. The joys of windows ;)
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 10084
  • FPC developer.
Re: [SOLVED] Console program opens new console on Windows?
« Reply #9 on: May 08, 2012, 01:18:43 pm »
The buildfaq topic on install.exe has a link to MSDN:

http://www.stack.nl/~marcov/buildfaq/#toc-Subsection-2.4.3

Note: manifests are a pain. Simply putting a manifest file next to it is not enough. It has to be installed by a windows installer.

(try just copying ginstall* from the FPC dir to a new dir)
« Last Edit: May 08, 2012, 01:24:52 pm by marcov »

ludob

  • Hero Member
  • *****
  • Posts: 1173
Re: [SOLVED] Console program opens new console on Windows?
« Reply #10 on: May 08, 2012, 01:25:16 pm »
Strangely enough the Vista Enterprise version I ran did bring up the UAC window. So MS fixed that at one moment before relaxing it for win7.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 10084
  • FPC developer.
Re: [SOLVED] Console program opens new console on Windows?
« Reply #11 on: May 08, 2012, 01:39:44 pm »
Correction to self, it works ok if I copy ginstall.exe + ginstall.manifest in one go.

Maybe the first case was that the program was already started and some attribute was set on it (probably in a secondary filestream)

Update: YES it is a filestream. Truncate can be done with "chmls unblock filename".

So.

If you have this problem

1. copy the one of the manifest files from the fpc dir and rename it (e.g. from ginstall.exe.manifest to yourappnamewithupdate.exe.manifest)
2. Since you probably already have run "yourappnamewithupdate" once, run chmls unblock on it.
3. It will probably work now.
« Last Edit: May 08, 2012, 01:42:04 pm by marcov »

 

TinyPortal © 2005-2018