tag:blogger.com,1999:blog-524230429673765509.post6542608901021032315..comments2023-11-05T00:53:40.301-07:00Comments on pyright: subprocess.Popen() or Abusing a Home-grown Windows ExecutableCarl Trachtehttp://www.blogger.com/profile/12363048245012413049noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-524230429673765509.post-91877654200268311342014-10-28T07:01:06.955-07:002014-10-28T07:01:06.955-07:00@Brett Thank you. Those suggestions are really go...@Brett Thank you. Those suggestions are really good. If I need to improve on this, I'll take your input and investigate it. I know from reading (mostly job announcements) that PyQt gets used a bit in scientific apps that require a GUI. Right now, the hack I presented gets the job done, but it definitely could use improvement. CBTCarl Trachtehttps://www.blogger.com/profile/12363048245012413049noreply@blogger.comtag:blogger.com,1999:blog-524230429673765509.post-56964446927377996372014-10-28T06:50:15.790-07:002014-10-28T06:50:15.790-07:00I also have to deal a lot with running Windows exe...I also have to deal a lot with running Windows executables in batch / parallel. For me it's typically running old compiled Fortran-based analysis codes across a range of inputs. I'm often wrapping these tools or (workflows involving several tools) into a GUI that streamlines things. This lead me to using PyQt and then PySide (more openly licensed Python Qt bindings). The great thing I discovered was that Qt's QProcess object can perform asynchronous interaction with executables. There are events/signals that get triggered like QProcess.readyReadStandardOutput or QProcess.readyReadStandardError that allow you to respond to specific queries asked by the executable. In the callback/slot connected to the readyReadStandardOutput signal you specify what to do in response, which can be to write text to the process. Like I check for "Press to continue" then automatically write a Return character to the process. My codes often output lines to the command window indicating progress, which I parse into a percentage and use to update a progress bar, and possibly a countdown timer. There is also a signal for when the process is finished so that you can perform cleanup or post-processing on the Python side. I've enjoyed PySide's signals and slots enough that I've even used it without GUI's to write asynchronous / event-based command line stuff. In fact, I've found it's best if your automation code works independent of the GUI, and then the start/stop/progress/finished signals can be connected to the GUI later without affecting functionality.<br /><br />You may not have the ability to install extra stuff in your environment. If not, since you're on Python3, perhaps the new asyncio module in 3.4 can interact with processes? I'm sure there are other libraries lighter than Qt than can handle reading the stdout pipe and writing to stdin interactively. Here's some interesting discussion which shows a wide range of solutions: http://stackoverflow.com/questions/375427/non-blocking-read-on-a-subprocess-pipe-in-python?lq=1. Some of the later answers on there are library implementations of the top answer.Anonymoushttps://www.blogger.com/profile/12957347205662383230noreply@blogger.com