Page 1 of 1 1
Topic Options
#212587 - 2017-07-14 04:41 AM Problems retrieving output from powershell command
IanDubbelboer Offline
Fresh Scripter

Registered: 2004-06-25
Posts: 24
Hello all

I have been knocking my head on this issue and would love a second opinion.

So I am trying to identify if an application is running and if so, see if that process is hung or not. The remainder of the code not shown Taskkills the task if it is not responding and restarts it. That part should be working fine.

 Code:
;Define Tasklist command
   $CMDAPPCheck = '%COMSPEC% /c tasklist'

;Run Tasklist command and feed output into array
   $APPCheckOut = Split($System.Shell($CMDAPPCheck,0,3), @CRLF)

;Parse array to see if APP I want to check for is running
   $EDIRUNOutput = AScan($APPCheckOut, $EDIApp, , , 3)

;Find PID of task I am looking for
   $EDIPID = SUBSTR($APPCheckOut[$EDIRUNOutput[0]], 27, 8)

;Specify powershell command to see if pid is responding
   $CMDAPPLocked = '%COMSPEC% /c powershell (get-process -id $EDIPID).responding'

;Run powershell command and feed output into array
   $APPLockOut = Split($System.Shell($CMDAPPLocked,0,3), @CRLF)



This is where things break. When the command runs in CMD I get back True if the app is responding.

When I run the code above in KIX 4.66 on Server 2008 R2 the debug step through locks up at this point. This code seems to work fine on Windows 7.

Plan B

I tried working the same idea but with Shell %COMSPEC% /c powershell (get-process -id) ).responding >C:\temp\out.txt

this works in debug but if I package it in Kix2EXE the file C:\temp\out.txt is blank.

Any idea what I am missing?

Top
#212588 - 2017-07-14 04:43 AM Re: Problems retrieving output from powershell command [Re: IanDubbelboer]
IanDubbelboer Offline
Fresh Scripter

Registered: 2004-06-25
Posts: 24
Oh sorry for input sake.

$EDIAPP = Any currently running APP exe

Top
#212589 - 2017-07-14 09:55 AM Re: Problems retrieving output from powershell command [Re: IanDubbelboer]
Arend_ Moderator Offline
MM club member
*****

Registered: 2005-01-17
Posts: 1894
Loc: Hilversum, The Netherlands
I wrote a Function that does this a while ago, it can be found here
Top
#212593 - 2017-07-14 04:49 PM Re: Problems retrieving output from powershell command [Re: Arend_]
IanDubbelboer Offline
Fresh Scripter

Registered: 2004-06-25
Posts: 24
Process murder is not actually the problem \:\)

Identifying the process is not responding be fore killing it is. The only way I have found to do it was via powershell

Top
#212595 - 2017-07-14 10:29 PM Re: Problems retrieving output from powershell command [Re: IanDubbelboer]
Allen Administrator Online   shocked
KiX Supporter
*****

Registered: 2003-04-19
Posts: 4545
Loc: USA
If you really need Powershell, a couple of options.
1. http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=199178#Post199178
2. http://www.kixtart.org/forums/ubbthreads.php?ubb=showflat&Number=83201

Top
#212598 - 2017-07-18 12:50 AM Re: Problems retrieving output from powershell command [Re: Allen]
IanDubbelboer Offline
Fresh Scripter

Registered: 2004-06-25
Posts: 24
So turns out the code does work.

Install this first to get powershell up to version 3

https://www.microsoft.com/en-ca/download/details.aspx?id=40855

Top
Page 1 of 1 1


Moderator:  Glenn Barnas, NTDOC, Arend_, Jochen, Radimus, Allen, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
1 registered (Allen) and 466 anonymous users online.
Newest Members
gespanntleuchten, DaveatAdvanced, Paulo_Alves, UsTaaa, xxJJxx
17864 Registered Users

Generated in 0.055 seconds in which 0.022 seconds were spent on a total of 13 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org