New topic: Shell.PID
<http://forums.realsoftware.com/viewtopic.php?t=45991> Page 1 of 1 [ 1 post ] Previous topic | Next topic Author Message ALoren Post subject: Shell.PIDPosted: Tue Nov 20, 2012 3:19 am Joined: Tue Nov 20, 2012 2:32 am Posts: 1 So there seems to be some confusion as to what the Shell.PID returns. Let me describe what I'm trying to do. I am creating a GUI for a command line program for Windows. I launch that program with shell.execute and that part is fine. While the command line program is processing a file, if I quit my GUI then the command line program continues running. I want to kill the process on close or on a cancel action. Shell.PID doesn't seem to return a PID used by any currently running program so I can't use it in conjunction with taskkill. I don't want to rely on WFS's classes and methods (Win32 API based) because I want to find a technique that can be ported to Mac fairly easily. I also can't rely on any technique that kills a task based on task name because I want to limit what is killed to what was launched specifically by my GUI; I want to rely on parent/child PIDs Currently I am using the following technique: - I shell execute cmd.exe (this creates two instances of cmd.exe) in interactive mode - I write the command "title=SomeIdentifier" to change the title of my commandline window (this doesn't work if I directly run it using shell execute, thus the redundancy of executing cmd.exe first) - I write the command "tasklist /v /fo csv | findstr /i SomeIdentifier" which returns a match based on window title, and I can pull the PID from the result - I save the PID as a variable so I can kill it and its child processes later, after it has launched the actual program I want It doesn't feel ideal, but I imagine it's easily adaptable to Mac because of the Unix-like terminal and the use of grep, etc. Does anyone have a more elegant solution? //from sub shell1.Execute("cmd.exe") shell1.writeline("title=MyProgram") shell1.WriteLine("tasklist /v /fo csv | findstr /i " + Chr(34) + "MyProgram" + Chr(34)) //chr 34 are double quotes " for proper command line usage //above line returns lines from the task list in csv form like "cmd.exe","3716","Console","1","6,276 K","Running","My-PC\Me","0:00:00","C:\Windows\System32\cmd.exe" shell1.writeline("AppIWantToControl.exe -flag") // from shell1.dataAvailable() Dim rg As New RegEx Dim myMatch As RegExMatch cmdbuffer = Me.readall //Grabs PID for later termination mid-process rg.SearchPattern=Chr(34) + "cmd.exe" + Chr(34) + "," + Chr(34) + "(\d+)" + Chr(34) //matches the second field from the above result, 3716 in this example myMatch=rg.search(cmdbuffer) Top Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending Page 1 of 1 [ 1 post ] -- Over 1500 classes with 29000 functions in one REALbasic plug-in collection. The Monkeybread Software Realbasic Plugin v9.3. http://www.monkeybreadsoftware.de/realbasic/plugins.shtml [email protected]
