Recent

Author Topic: Getting rid of the console screen when calling R from Lazarus application  (Read 2707 times)

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Dear ALL,

For many moons have I been struggling with an annoying problem which, being annoying, only appears under MS-Windows. Since it is not a critical problem, just a cosmetic one, I have postponed it but now it is time to tackle it seriously in the hope of solve it at once!

Notice that this problem only affects MS-Windows and to be checked it requires a local installation of the R system for statistical computing and graphics (freely available from here: http://www.r-project.org/)!

So, for the problem itself: I want to call R from a FPC/Lazarus program, passing it a script file with valid commands in the R language. For that, I use the handy, multiplatform, RunCommand from the Process FPC/Lazarus unit. It works fine - except that, under MS-Windows, an ugly (empty) console screen is flashed in the face of the user, even if the "poNoConsole" flag is properly set! Needless to say, this problem does not appear under GNU/Linux, where R is called without any console screen being displayed.

Why is this so? May best guess (which may be completely wrong) is that to execute an external program, MS-Windows in fact calls the command interpreter "C:\Windows\System32\cmd.exe" and therefore the poNoConsole and other RunCommand flags have no effect because they should in fact be passed to the command interpreter and not to the process being called by the function.

I hope that there is some little, but arcane, trick to solve this problem (out there, where the truth is!). Presuming it does exist, could someone kindly share it with me?

To illustrate the problem, I attach a very simple sample project.

Thanks in advance for any assistance you can provide.

With best wishes,
« Last Edit: October 14, 2021, 01:20:58 am by maurobio »
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

wp

  • Hero Member
  • *****
  • Posts: 11906
I do see the flashing console window on Win10 when I use Laz 1.8.4 or Laz 2.0.8 - these are the versions mentioned in your signature; they are based on FPC 3.0.4. However, when I go to Laz 2.0.10 or 2.0.12, based on FPC 3.2.0, or Laz 2.2RC1 or main, based on FPC 3.2.2, the console Window does not appear any more. This is for your RunCommand and ExecuteR variants, for SysUtils.ExecuteProcess, however, the console window is back.

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Hi, @wp!

Thanks for the tip! But should I really need to upgrade my Lazarus installation in order to get rid of this annoying problem? Anyway, I will look into it ASAP.

With best wishes,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

wp

  • Hero Member
  • *****
  • Posts: 11906
Well, tons of bugs are fixed in newer Lazarus and FPC versions. So don't complain about these bugs when you refuse to update.

Maybe you don't know, but you can always install several Lazarus versions in parallel and use them independently (I have more than 20 versions on my desktop plus some others in virtual machines). This way you can continue your work on your old version, but occasionally you can compile with newer versions and adjust your sources so that they compile on all versions - then you are ready for the future. (Work on backup sources when you switch versions because new versions may add new properties so that lfm files may not load any more when you return).
« Last Edit: October 13, 2021, 01:16:15 am by wp »

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Well, tons of bugs are fixed in newer versions. So don't complain about these bugs when you refuse to update.

Well, @wp, I did not see that problem as a "bug" of Lazarus, but as some limitation of MS-Windows....  :-[

With best wishes,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

PascalDragon

  • Hero Member
  • *****
  • Posts: 5462
  • Compiler Developer
Well, tons of bugs are fixed in newer versions. So don't complain about these bugs when you refuse to update.

Well, @wp, I did not see that problem as a "bug" of Lazarus, but as some limitation of MS-Windows....  :-[

In this case FPC 3.0.4 did pass along the wrong flag to Windows when poNoConsole was provided, that's why it didn't work there, but works in 3.2.0 and newer (where the correct flag is passed along).

maurobio

  • Hero Member
  • *****
  • Posts: 623
  • Ecology is everything.
    • GitHub
Hi, @PascalDragon!

Thanks. I got the problem solved at once by upgrading my installation of FPC/Lazarus (as so emphatically suggested by @wp). I have also took this opportunity to standardize my installation of FPC/Lazarus all across the systems I have in use (Win32/64 and Linux32/64).

With best wishes,
UCSD Pascal / Burroughs 6700 / Master Control Program
Delphi 7.0 Personal Edition
Lazarus 2.0.12 - FPC 3.2.0 on GNU/Linux Mint 19.1, Lubuntu 18.04, Windows XP SP3, Windows 7 Professional, Windows 10 Home

 

TinyPortal © 2005-2018