Lazarus

Free Pascal => General => Topic started by: Emerson on July 29, 2021, 12:24:29 am

Title: RunCommand
Post by: Emerson on July 29, 2021, 12:24:29 am
Hi!
   
    I have a problem when executing a command with RunCommand.
    When running the same, a black prompt screen appears and I would like to hide.
   
    Can someone help me?

RunCommand('cmd.exe', ['/c', v_comando], v_resultado_da_exec_shell);
Title: Re: RunCommand
Post by: sstvmaster on July 29, 2021, 10:45:21 am
You also can use TProcess, see: https://wiki.freepascal.org/Executing_External_Programs

or you can set the TShowWindowOptions property:
- https://www.freepascal.org/docs-html/fcl/process/runcommand.html
- https://www.freepascal.org/docs-html/fcl/process/tshowwindowoptions.html
Title: Re: RunCommand
Post by: BobDog on July 29, 2021, 12:53:04 pm

For windows to access the command shell you can do:
Code: Pascal  [Select][+][-]
  1.   program shell;
  2.  
  3. function  system(s:pchar):integer ; cdecl external 'msvcrt.dll' name 'system';
  4. function  wsystem(s:widestring):integer ; cdecl external 'msvcrt.dll' name '_wsystem';
  5.  
  6.  
  7. procedure speak(text:ansistring);
  8. var x:ansistring;
  9. begin
  10.      x:='mshta vbscript:Execute("CreateObject(""SAPI.SpVoice"").Speak(""'+text+'"")(window.close)")';
  11.       system(pchar(x)) ;
  12.   end;
  13.  
  14.  
  15. begin
  16. system('help');
  17. speak('thank you, goodbye');
  18. readln;
  19. end.
and get all those old dos commands or powershell commands
wsystem is optional for widestrings.
Title: Re: RunCommand
Post by: sstvmaster on July 29, 2021, 02:44:49 pm
@Emerson

Code: Pascal  [Select][+][-]
  1. RunCommand('cmd.exe', ['/c', v_comando], v_resultado_da_exec_shell, [], swoHIDE);
Title: Re: RunCommand
Post by: Emerson on August 02, 2021, 02:04:51 pm
Hi! The answer from the sstv master friend was successful. Thanks everyone for responding.
TinyPortal © 2005-2018