bernhard_LA 0 Posted November 6, 2019 I need a solution to replace the shellexecute command for the windows platform If possible no external / 3rd party lib involved Can someone provide a working code here ? Share this post Link to post
David Heffernan 2345 Posted November 6, 2019 There is no way to replace all the functionality of ShellExecute which encompasses the entire shell verb mechanism in Windows. What specific functionality of ShellExecute are you looking to replicate? Share this post Link to post
bernhard_LA 0 Posted November 6, 2019 Basic Wish a) just start a executeable like ./myapplication and pass also command line parameters Advanced Wish b) a notification once the ./myappliaction is finished work around i) any solution using RAD C++ and Linux compile options ?? ii) call a phyton script from Delphi ???? iii) a dll written in Lazarus ????? Share this post Link to post
ergeka 5 Posted November 6, 2019 Perhaps this gives an idea. https://chapmanworld.com/2017/04/06/calling-linux-commands-from-delphi/ 3 Share this post Link to post
Remy Lebeau 1400 Posted November 6, 2019 (edited) 4 hours ago, bernhard_LA said: a) just start a executeable like ./myapplication and pass also command line parameters b) a notification once the ./myappliaction is finished Why were you using ShellExecute() for that? You should have been using CreateProcess() instead. To detect when the process ends, use WaitForSingleObject() or related function on the returned process handle. On Linux, you can start an external process using the fork(), exec...(), or posix_spawn() functions. To detect when the process ends, use wait() on the returned process ID. Edited November 6, 2019 by Remy Lebeau 3 Share this post Link to post
David Heffernan 2345 Posted November 6, 2019 No need for a workaround. Creating processes, and waiting for them to terminate is routine stuff on all platforms. Definitely worth seconding everything that @Remy Lebeau said. You don't want to replicate ShellExecute because you don't want to use it at all. ShellExecute is used to execute shell verbs. But you want to create a process. A quite different thing altogether. Albeit the open verb on an executable file often results in a new process being created. Share this post Link to post
Fr0sT.Brutal 900 Posted November 7, 2019 Lazarus has multiplatform TProcess with STDIN/OUT interception, waiting for finish and so on. I wonder if something like that exists for Delphi (this should really be in RTL as it's "routine stuff") 1 Share this post Link to post
Remy Lebeau 1400 Posted November 7, 2019 12 hours ago, Fr0sT.Brutal said: Lazarus has multiplatform TProcess with STDIN/OUT interception, waiting for finish and so on. I wonder if something like that exists for Delphi There is nothing like FPC's TProcess in Delphi's RTL. I'm sure you can find a 3rd party implementation, though. Or just write your own. Share this post Link to post
Fr0sT.Brutal 900 Posted November 8, 2019 12 hours ago, Remy Lebeau said: There is nothing like FPC's TProcess in Delphi's RTL. I'm sure you can find a 3rd party implementation, though. Or just write your own. I know there isn't but Idera really should think about adding one. 3 Share this post Link to post
Ugochukwu Mmaduekwe 42 Posted November 8, 2019 Here is an attempt by someone to implement FPC awesome TProcess in Delphi. May be someone else can work on extending it with Linux support. Share this post Link to post
Joseph MItzen 251 Posted November 8, 2019 On 11/7/2019 at 1:50 AM, Fr0sT.Brutal said: Lazarus has multiplatform TProcess with STDIN/OUT interception, waiting for finish and so on. I wonder if something like that exists for Delphi (this should really be in RTL as it's "routine stuff") I know David Heffernan and I have debated this before , but IMHO no, there's nothing like Lazarus' TProcess, Qt's QProcess, or Python's run function in Delphi (David disagrees). I also am puzzled why Delphi has never had a simple way to execute commands and retrieve results. Share this post Link to post
David Heffernan 2345 Posted November 8, 2019 25 minutes ago, Joseph MItzen said: David disagrees If I actually disagreed with you, I'd produce a counter example. I don't think I have because I don't think there is one. Therefore I can't believe that I disagree. Share this post Link to post
Joseph MItzen 251 Posted November 9, 2019 1 hour ago, David Heffernan said: If I actually disagreed with you, I'd produce a counter example. I don't think I have because I don't think there is one. Therefore I can't believe that I disagree. OK, I think I recalled the disagreement somewhat wrong. It was about being able to call a process and get its output back into Delphi. I cited the standard code examples per https://stackoverflow.com/questions/9119999/getting-output-from-a-shell-dos-app-into-a-delphi-app and opined that it was rather complicated. You offered another method and argued that it wasn't really very hard at all. Share this post Link to post
Dave Nottage 557 Posted October 14 On 11/7/2019 at 4:31 AM, ergeka said: https://chapmanworld.com/2017/04/06/calling-linux-commands-from-delphi/ For anyone else coming across this link, it has moved to: https://chapmanworld.com/calling-linux-commands-from-delphi/ 1 1 Share this post Link to post