[fpc-pascal] Windows console

Santiago A. svaa at ciberpiula.net
Tue Sep 6 11:44:44 CEST 2016


El 05/09/2016 a las 16:26, José Mejuto escribió:
> El 05/09/2016 a las 15:01, Santiago A. escribió:
>> Hello:
>>
>> I have a little watchdog utility for windows that runs each five
>> minutes, like a unix cron ("Tareas programadas" in Spanish, scheduled
>> tasks?). It opened a console window for a second and that was very
>> annoying. So I used the switch -GW and there is no more flashing console
>> bothering. But then I can't show any help or any output for debug from
>> the prompt.
>>
>> I can live with it, in fact, it usually uses a log file, but some times,
>> when I'm installing, testing paramters etc, it's more handy to run the
>> program from the prompt and see the result immediately or display the
>> help instead of having to open logs.
>>
>> Is there any way to open a console on the fly and send the output to the
>> console?
> 
> Hello,
> 
> I would create a .bat file in temp folder and run a new shell execute of
> that .bat. This .bat simply display some echo lines and finally autokill
> itself.
> 
> If your system for security reasons do not allow run bats then you can
> create a .txt file and launch a shell execute cmd with "type
> \path\file.txt" (keeping session open or it will clear the screen). You
> main program can wait 2-5 seconds and delete the .txt file to not
> pollute the temp folder.
> 
> Of course this is a "home made" solution :) Another is have a different
> exe just for the help, have a .bat or .txt in your app folder just to
> show the help if it is always the same, ...

I have found a solution here:

http://stackoverflow.com/questions/20134421/can-a-windows-gui-program-written-in-lazarus-create-a-console-and-write-to-it-at

At least it works for windows

uses
  Windows;
begin
  AllocConsole;      // in Windows unit
  IsConsole := True; // in System unit
  SysInitStdIO;      // in System unit
  // Now you can do Writeln, DebugLn, ...
end.




More information about the fpc-pascal mailing list