wxinix 0 Posted January 1 I am looking for a Delphi subprocess library, something like Python's subprocess - is there one? Share this post Link to post
dummzeuch 1505 Posted January 1 (edited) 43 minutes ago, wxinix said: I am looking for a Delphi subprocess library, something like Python's subprocess - is there one? If I understood this correctly, a Python subprocess starts an external program, connects its stdin/out/err to pipes and gets the return code when it exits. There is nothing like this in the standard Delphi RTL but there are multiple third party options. If I remember correctly one is in the JCL, another is my own TAsyncExec class in unit u_dzAsyncExec which is part of my dzlib library. Edited January 1 by dummzeuch 1 1 Share this post Link to post
Darian Miller 361 Posted January 1 There's quite a few options out there. I wrote a related blog post and provided some example code: https://ideasawakened.com/post/use-createprocess-and-capture-the-output-in-windows 2 Share this post Link to post
lmbelo 2 Posted July 18 There are some related operations here: https://github.com/Embarcadero/PythonEnvironments/tree/main/src/Tools/ExecCmd Share this post Link to post
JonRobertson 72 Posted July 18 There is also TProcess, ported from Lazarus lcl. I've never used it and the last update was 7 years ago. I suspect most Delphi developers use CreateProcess, as long as the project is Windows only. See Darian's link above. Here are a few others: https://www.delphibasics.info/home/delphibasicssnippets/createprocessandwaitforexit http://www.delphicorner.f9.co.uk/articles/wapi4.htm https://riptutorial.com/delphi/example/18340/createprocess Share this post Link to post
Patrick PREMARTIN 74 Posted July 19 Isn't it what TDosCommand does ? (for Windows only) https://github.com/TurboPack/DOSCommand 1 Share this post Link to post
corneliusdavid 214 Posted July 19 7 hours ago, Patrick PREMARTIN said: Isn't it what TDosCommand does ? (for Windows only) That's what I was thinking. DosCommand works great and is pretty easy to use--no need to get into the intricacies of CreateProcess. 1 Share this post Link to post
JonRobertson 72 Posted July 19 22 minutes ago, corneliusdavid said: DosCommand works great and is pretty easy to use--no need to get into the intricacies of CreateProcess. Python's subprocess does more than DOS / command line stuff. How well does TDOSCommand work with Windows executables? Share this post Link to post
corneliusdavid 214 Posted July 19 AutoGetIt uses it to launch batch files. The only problem I've had is that sometimes partial lines are returned as full lines, then the next NewLine event returns the full line. Not sure if this is a problem in DosCommand or some OS-level buffering--never took the time to look deeply into it. Share this post Link to post
corneliusdavid 214 Posted July 19 3 minutes ago, corneliusdavid said: The only problem I've had is that sometimes partial lines are returned as full lines, then the next NewLine event returns the full line. Well, I feel silly. I just noticed a parameter in DosCommand's NewLine event that indicates whether it's a full line or not. Checking that now gives a cleaner log--no partial lines. So, yeah, DosCommand works great! 2 Share this post Link to post
pyscripter 689 Posted July 19 (edited) 29 minutes ago, JonRobertson said: Python's subprocess does more than DOS / command line stuff. You can always use the this python module from Delphi using P4D . One of the most advanced such Delphi functions in the Jcl unit JclSysUtils. Look at ExecuteCmdProcess and the various Execute overloads. It uses overlapped IO for super efficient redirection of the produced output, instead of using a special thread or a timer. These functions are also suitable for execution from a task/thread, if you do not want to block the main thread. The unit pyscripter/Source/uSysUtils.pas at master · pyscripter/pyscripter (github.com) extends the jcl functions to allow for an stdin pipe, customized environment variables and a buffered raw output. Edited July 19 by pyscripter Share this post Link to post
dummzeuch 1505 Posted July 19 2 hours ago, JonRobertson said: Python's subprocess does more than DOS / command line stuff. How well does TDOSCommand work with Windows executables? That was the problem with this topic from the beginning. What exactly is a "subprocess in python"? What does it do, if it is "more than DOS / command line stuff"? Share this post Link to post
JonRobertson 72 Posted July 19 2 minutes ago, dummzeuch said: What exactly is a "subprocess in python"? What does it do, if it is "more than DOS / command line stuff"? What is Python Subprocess Quote you can use the subprocess module to run a shell command, like "ls" or "ping", and get the output of that command in your Python code. You can also use it to run other Python scripts or executables, like .exe files on Windows. That's why I asked when others suggested TDOSCommand. From the github page, it only mentions command line apps. Share this post Link to post
dummzeuch 1505 Posted July 19 8 minutes ago, JonRobertson said: 9 minutes ago, JonRobertson said: you can use the subprocess module to run a shell command, like "ls" or "ping", and get the output of that command in your Python code. You can also use it to run other Python scripts or executables, like .exe files on Windows. What is Python Subprocess That's why I asked when others suggested TDOSCommand. From the github page, it only mentions command line apps. TDosCommand can run other Delphi programs and executables. It can even run python scripts, if the interpreter for that is installed. So I guess that fits the bill. Share this post Link to post