Different results running console program in Win10 and Win7 lazarus / 34-Windows ---------------------------------------------------------------------- vojtek · 2016-09-25 18:09 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i  ...     // compare CurrentFile with PatternImage    RunCommandInDir(FolderToProce ss,EDOPath.ImageMagick+'convert.exe',IM_Params,IM_Metric);     SetLength(IM_Metric,Length(IM_Metric)-2);   // remove LF and CR    Val(IM_Metric,FL[CurrentFile-1].Distortion,c);...  What the ImageMagick does (achieved by passing the IM_Params) is the following: reads the imagecrops and trims the imagewrites the resulting image to the png filecompares the resulting image with the pattern imagewrites the result (string) to TXT filewrites 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 resultsCalling 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 · 2016-09-25 19:05 Maybe the difference is actually in convert.exe ? The version, or its behaviour in various windows versions? ---------------------------------------------------------------------- engkin · 2016-09-25 20:20 Quote from: vojtek on September 25, 2016, 08:09:28 pmRunCommandInDir 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. Quote from: vojtek on September 25, 2016, 08:09:28 pm............writes the result (string) to TXT filewrites 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 · 2016-09-25 21:47 QuoteYour 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 · 2016-09-25 21:55 Quote from: vojtek on September 25, 2016, 11:47:57 pmQuoteYour 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i 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 · 2016-09-25 21:57 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 · 2016-09-25 22:05 QuoteYou 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 · 2016-09-25 22:38 Quote from: engkin on September 25, 2016, 10:20:14 pmQuote from: vojtek on September 25, 2016, 08:09:28 pmRunCommandInDir 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 · 2016-09-26 05:33 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/ ---------------------------------------------------------------------- vojtek · 2016-09-26 10:39 Quote from: Thaddy on September 26, 2016, 07:33:37 amMicrosoft 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 · 2016-09-26 19:03 Quote from: vojtek on September 26, 2016, 12:39:53 pmQuote from: Thaddy on September 26, 2016, 07:33:37 amMicrosoft 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 · 2016-09-26 19:07 And what happens if you avoid using that function and use by yourself directly TProcess or TProcessUTF8? ---------------------------------------------------------------------- vojtek · 2016-09-28 17:38 Quote from: lainz on September 26, 2016, 09:07:57 pmAnd 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 · 2016-09-28 18:23 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. ---------------------------------------------------------------------- vojtek · 2016-09-28 18:39 Quote from: Thaddy on September 28, 2016, 08:23:26 pmThen 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 ---------------------------------------------------------------------- omarG · 2016-09-29 19:16 I found that using WINDOWS prefix on Windows calls, fixed many problems for me on Windows 10 with fpc 3.0.  Never needed to do so in previous versions of either. ---------------------------------------------------------------------- vojtek · 2016-09-30 01:01 Quote from: omarG on September 29, 2016, 09:16:45 pmI found that using WINDOWS prefix on Windows calls, fixed many problems for me on Windows 10 with fpc 3.0.  Never needed to do so in previous versions of either. What do you mean by that?