Recent

Author Topic: Different results running console program in Win10 and Win7  (Read 9387 times)

vojtek

  • New Member
  • *
  • Posts: 10
Different results running console program in Win10 and Win7
« on: September 25, 2016, 08:09:28 pm »
Hi everyone,

I have just experienced a very strange behaviour and got stuck...

I have written a console program which works pretty well in Windows7 but gives strange, unpredictable and not repeatable results when executed in Windows10.

If executed in Win10 it runs properly producing no errors however the results are slightly different from those produced if executed in Windows7.

The code basically calls the ImageMagick using RunCommandInDir and gets IM_Metric string in return (see below)
Code: Pascal  [Select][+][-]
  1.  ...  
  2.    // compare CurrentFile with PatternImage
  3.     RunCommandInDir(FolderToProcess,EDOPath.ImageMagick+'convert.exe',IM_Params,IM_Metric);
  4.  
  5.     SetLength(IM_Metric,Length(IM_Metric)-2);   // remove LF and CR
  6.     Val(IM_Metric,FL[CurrentFile-1].Distortion,c);
  7. ...
  8.  

What the ImageMagick does (achieved by passing the IM_Params) is the following:
  • reads the image
  • crops and trims the image
  • writes the resulting image to the png file
  • compares the resulting image with the pattern image
  • writes the result (string) to TXT file
  • writes the result (string) to StdOut (passes to my program)

I made a lot of tests and the outcome is the following:
  • Running ImageMagick alone (just from console and not from my program) works fine both in Win7 and Win10
  • Calling ImageMagick from my program in Win7 gives correct results
  • Calling ImageMagick from my program in Win10 gives correct results except p.6 above (passing the information back to my program). Occasionally instead of passing the right data it passes "0" and it does not follow any pattern: processing 662 image files may give 0, 1, 2, 3 or more (different every time) wrong results ("0") passed to my program...
  • Calling ImageMagick from my program in Win10 but running my program with Compatibility Mode set to Windows7 gives correct results

I tried to find some switches for the compiler that would help sorting this out but failed to find anything useful...

Program is compiled for Win64 using FPC 3.0.0 with Lazarus 1.6 (SVN 51630) running in Win7 64bit

Does anyone of you experienced anything similar?
Would appreciate any help that could move me forward..

Thanks in advance!
Wojtek

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11382
  • FPC developer.
Re: Different results running console program in Win10 and Win7
« Reply #1 on: September 25, 2016, 09:05:14 pm »
Maybe the difference is actually in convert.exe ?

The version, or its behaviour in various windows versions?

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Different results running console program in Win10 and Win7
« Reply #2 on: September 25, 2016, 10:20:14 pm »
RunCommandInDir and gets IM_Metric string in return ...
I would check RunCommandInDir result and use the version that gives exitstatus and check its value as well.

  • ...
  • ...
  • ...
  • ...
  • writes the result (string) to TXT file
  • writes the result (string) to StdOut (passes to my program)
  • ...
  • ...
  • Calling ImageMagick from my program in Win10 gives correct results except p.6 above ...
Your description implies that p. 5 is OK which, if true, means the problem is in writing the result to StdOut. If this is the case then you might want to share the code related to that part.

vojtek

  • New Member
  • *
  • Posts: 10
Re: Different results running console program in Win10 and Win7
« Reply #3 on: September 25, 2016, 11:47:57 pm »
Quote
Your description implies that p. 5 is OK which, if true, means the problem is in writing the result to StdOut. If this is the case then you might want to share the code related to that part.

The RunCommandInDir code is part of the unit process which is part of the Free Component Library (FCL) ...

So I believe it is available to everyone as a part of the Lazarus installation, right?

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: Different results running console program in Win10 and Win7
« Reply #4 on: September 25, 2016, 11:55:31 pm »
Quote
Your description implies that p. 5 is OK which, if true, means the problem is in writing the result to StdOut. If this is the case then you might want to share the code related to that part.

The RunCommandInDir code is part of the unit process which is part of the Free Component Library (FCL) ...

So I believe it is available to everyone as a part of the Lazarus installation, right?
Yes, that's why I suggested using this version:
Code: Pascal  [Select][+][-]
  1. function RunCommandIndir(const curdir:string;const exename:string;const commands:array of string;var outputstring:string;var exitstatus:integer):integer;

You still did not answer if your TXT file is correct?

vojtek

  • New Member
  • *
  • Posts: 10
Re: Different results running console program in Win10 and Win7
« Reply #5 on: September 25, 2016, 11:57:56 pm »
I don't think so...
Convert.exe runs OK on the same PC when executed just from command line and works OK when executed from my program...
It's just passing the result throught StdOut that does not work in Win10
So I guess something is wrong either in unit process or the way the program is compiled which is not liked by Win10...

vojtek

  • New Member
  • *
  • Posts: 10
Re: Different results running console program in Win10 and Win7
« Reply #6 on: September 26, 2016, 12:05:00 am »
Quote
You still did not answer if your TXT file is correct?
I thought it was clear from my original post...
Yes, the TXT file is/was OK every time...
It's just passing the result via StdOut which is not working properly from time to time when executing my program in Win10...

vojtek

  • New Member
  • *
  • Posts: 10
Re: Different results running console program in Win10 and Win7
« Reply #7 on: September 26, 2016, 12:38:04 am »
RunCommandInDir and gets IM_Metric string in return ...
I would check RunCommandInDir result and use the version that gives exitstatus and check its value as well.

Just followed your advice...
For every image processed the exitstatus=0 regardless if the passed string was correct or not (i.e. different to what can be found in the txt file and equals 0)...

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Different results running console program in Win10 and Win7
« Reply #8 on: September 26, 2016, 07:33:37 am »
Microsoft acutally completely rewrote the console in Windows 10.
Older software may experience problems and therefor there is an option to put the console itself in  legacy mode (differs from software in legacy mode, this is under console options) which will simply start a windows 7 console.
This is not a matter of FPC itself. I experienced this kind op issue myself and the solution works most of the time.
The software that conflicts should probably be rewritten taking the new features and API in consideration.

Here's a link to a blog about the subject:
https://blogs.windows.com/buildingapps/2014/10/07/console-improvements-in-the-windows-10-technical-preview/
Specialize a type, not a var.

vojtek

  • New Member
  • *
  • Posts: 10
Re: Different results running console program in Win10 and Win7
« Reply #9 on: September 26, 2016, 12:39:53 pm »
Microsoft acutally completely rewrote the console in Windows 10.
Older software may experience problems and therefor there is an option to put the console itself in  legacy mode (differs from software in legacy mode, this is under console options) which will simply start a windows 7 console.
This is not a matter of FPC itself. I experienced this kind op issue myself and the solution works most of the time.
The software that conflicts should probably be rewritten taking the new features and API in consideration.

Here's a link to a blog about the subject:
https://blogs.windows.com/buildingapps/2014/10/07/console-improvements-in-the-windows-10-technical-preview/

Thanks Thaddy - It looks like it may solve my problem :)
I'll give it a try today and post the results!

vojtek

  • New Member
  • *
  • Posts: 10
Re: Different results running console program in Win10 and Win7
« Reply #10 on: September 26, 2016, 09:03:38 pm »
Microsoft acutally completely rewrote the console in Windows 10.
Older software may experience problems and therefor there is an option to put the console itself in  legacy mode (differs from software in legacy mode, this is under console options) which will simply start a windows 7 console.
This is not a matter of FPC itself. I experienced this kind op issue myself and the solution works most of the time.
The software that conflicts should probably be rewritten taking the new features and API in consideration.

Here's a link to a blog about the subject:
https://blogs.windows.com/buildingapps/2014/10/07/console-improvements-in-the-windows-10-technical-preview/

Thanks Thaddy - It looks like it may solve my problem :)
I'll give it a try today and post the results!

As promissed I gave this a try with high hopes...

It's sad to say that nothing has changed, still:
  • TXT is OK (always = for every image processed)
  • data passed via StdOut is not corrrect for few cases/images (random)
  • exitstatus is always 0

seems that changes MS did to console is not a reason for the issues I experience...

Any other ideas / hints?

So far the only solution that works is running my program in Win7 compatibility mode...

lainz

  • Hero Member
  • *****
  • Posts: 4460
    • https://lainz.github.io/
Re: Different results running console program in Win10 and Win7
« Reply #11 on: September 26, 2016, 09:07:57 pm »
And what happens if you avoid using that function and use by yourself directly TProcess or TProcessUTF8?

vojtek

  • New Member
  • *
  • Posts: 10
Re: Different results running console program in Win10 and Win7
« Reply #12 on: September 28, 2016, 07:38:05 pm »
And what happens if you avoid using that function and use by yourself directly TProcess or TProcessUTF8?

I've never used that before but I guess I will need to give it a try...
(but this will require some time to learn...)

Any good examples of how it can/should be done?

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Different results running console program in Win10 and Win7
« Reply #13 on: September 28, 2016, 08:23:26 pm »
Then it may be a codepage issue:
What are the results when you type "chcp" in a console window on the win7 machine  and the win10 machine.
If they are different we can solve the issue quickly.
Please report back the results.
Specialize a type, not a var.

vojtek

  • New Member
  • *
  • Posts: 10
Re: Different results running console program in Win10 and Win7
« Reply #14 on: September 28, 2016, 08:39:02 pm »
Then it may be a codepage issue:
What are the results when you type "chcp" in a console window on the win7 machine  and the win10 machine.
If they are different we can solve the issue quickly.
Please report back the results.


Win7: 852
Win10: 852
« Last Edit: September 28, 2016, 08:45:22 pm by vojtek »

 

TinyPortal © 2005-2018