Jump to content
bernhard_LA

Shellexecute @ UBUNTU platform

Recommended Posts

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

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

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
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 by Remy Lebeau
  • Like 3

Share this post


Link to post

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

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")

  • Like 1

Share this post


Link to post
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
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.

  • Like 3

Share this post


Link to post
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 :classic_biggrin:, 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
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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×