Recent

Author Topic: Help to windows cmd.  (Read 3175 times)

nocuttree

  • New Member
  • *
  • Posts: 36
Help to windows cmd.
« on: September 22, 2014, 01:01:12 pm »
Hello all, I am using this code
Code: [Select]
if ShellExecute(0,nil, PChar('cmd'),PChar('/c mybatch.bat'),nil,1) =0 then;
to run a bacth file. I want to hide this windows cmd and have a command to wait this windows cmd close.
Thanks to all!
Sorry my English, Windows xp, Lazarus 1.2.2!

Mike.Cornflake

  • Hero Member
  • *****
  • Posts: 1260
Re: Help to windows cmd.
« Reply #1 on: September 22, 2014, 01:15:31 pm »
I don't think you can wait with ShellExecute.  I think it fires off the command and immediately returns to code, letting the command run in another process.

You can TProcess.  It's cross platform and the preferred method

http://wiki.lazarus.freepascal.org/Executing_External_Programs

Just ensure you have poWaitOnExit in the options.  Err, and there's another po for Hide - ahh, poNoConsole...

Extending the Simple Example in the wiki change this line...

Code: [Select]
AProcess.Options := AProcess.Options + [poWaitOnExit, poNoConsole];
Lazarus Trunk/FPC Trunk on Windows [7, 10]
  Have you tried searching this forum or the wiki?:   http://wiki.lazarus.freepascal.org/Alternative_Main_Page
  BOOKS! (Free and otherwise): http://wiki.lazarus.freepascal.org/Pascal_and_Lazarus_Books_and_Magazines

nocuttree

  • New Member
  • *
  • Posts: 36
Re: Help to windows cmd.
« Reply #2 on: September 25, 2014, 01:51:52 pm »
I don't think you can wait with ShellExecute.  I think it fires off the command and immediately returns to code, letting the command run in another process.

You can TProcess.  It's cross platform and the preferred method

http://wiki.lazarus.freepascal.org/Executing_External_Programs

Just ensure you have poWaitOnExit in the options.  Err, and there's another po for Hide - ahh, poNoConsole...

Extending the Simple Example in the wiki change this line...

Code: [Select]
AProcess.Options := AProcess.Options + [poWaitOnExit, poNoConsole];
Thanks you!
Sorry my English, Windows xp, Lazarus 1.2.2!

 

TinyPortal © 2005-2018