Sign in to follow this  
Followers 0
Nevi

ProcessList | Error : Subscript used on non-accessible variable.

10 posts in this topic

Could anyone show me what's wrong here?

Func _getPID($ProcessName)


Local $i = 0
Local $PID = 0


While ( $i + 1 <= ProcessList($ProcessName)[0][0] )
$PID[$i] = ProcessList($ProcessName)[$i+1][1] ; probably this one.
$i = $i + 1
WEnd


Return ($PID)


EndFunc




_getPID("explorer.exe")

Thank you.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Why not just use

ProcessList('explorer.exe')

?

EDIT: If you have the error please post it, I bet it is has to do with the fact that your trying to use a regular variable as an array like so

$PID[$i]
Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

ProcessList -

Returns an array listing the currently running processes (names and PIDs).

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

ProcessList -

Returns an array listing the currently running processes (names and PIDs).

Thanks. However, how do you list the PID of multiple processes with the same name?

I'm a bit confused, now.

 

PS: The error is in the title. Sorry for the confusion.

Edited by Nevi

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Return Value
Success:    an array of process names and PIDs (See Remarks).
Failure:    sets the @error flag to 1 when the array cannot be built.
Remarks
The array returned is two-dimensional and is made up as follows:
    $aArray[0][0] = Number of processes
    $aArray[1][0] = 1st Process name
    $aArray[1][1] = 1st Process ID (PID)
    $aArray[2][0] = 2nd Process name
    $aArray[2][1] = 2nd Process ID (PID)
    ...
    $aArray[n][0] = nth Process name
    $aArray[n][1] = nth Process ID (PID)

The list can be empty if $aArray[0][0] = 0. No @error set in this case.

The helpfile is your friend ;)

If that wasn't clear it will list all running names and PIDs of the process.

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

You initalize $PID to 0, then call the function passing the ProcessName, but never do anything more with $PID. Why wouldn't you get an error? Try this to see why it is failing:

Func _getPID($ProcessName)
    Local $i = 0
    Local $PID = 0

    While ( $i + 1 <= ProcessList($ProcessName)[0][0] )
        If Not IsArray($PID) Then
            MsgBox(0, "", "$PID is NOT an array so $PID[$i] will FAIL. $PID = " & $PID)
            Exit
        EndIf
        $PID[$i] = ProcessList($ProcessName)[$i+1][1] ; probably this one.
        $i = $i + 1
    WEnd

    Return ($PID)
EndFunc




_getPID("explorer.exe")
Edited by JLogan3o13

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

 

You initalize $PID to 0, then call the function passing the ProcessName, but never do anything more with $PID. Why wouldn't you get an error? Try this to see why it is failing:

Func _getPID($ProcessName)
    Local $i = 0
    Local $PID = 0

    While ( $i + 1 <= ProcessList($ProcessName)[0][0] )
        If Not IsArray($PID) Then
            MsgBox(0, "", "$PID is NOT an array so $PID[$i] will FAIL. $PID = " & $PID)
            Exit
        EndIf
        $PID[$i] = ProcessList($ProcessName)[$i+1][1] ; probably this one.
        $i = $i + 1
    WEnd

    Return ($PID)
EndFunc




_getPID("explorer.exe")

 

This will fail everytime. obviously it will, but isn't doing this much work a little redundant or am I just being dumb?

Edited by MikahS

Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

Precisely the point I am trying to make - the OP is asking why his code is failing. That demonstrates why.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Precisely the point I am trying to make - the OP is asking why his code is failing. That demonstrates why.

 

Thank you very very much!

Share this post


Link to post
Share on other sites

 

EDIT: If you have the error please post it, I bet it is has to do with the fact that your trying to use a regular variable as an array like so

$PID[$i]

 

Precisely the point I am trying to make - the OP is asking why his code is failing. That demonstrates why.

 

Ah, I see they just skipped over ;)


Snips & Scripts


My Snips: graphCPUTemp ~ getENVvars
My Scripts: Short-Order Encrypter - message and file encryption V1.6.1 ~ AuPad - Notepad written entirely in AutoIt V1.9.4

Feel free to use any of my code for your own use.                                                                                                                                                           Forum FAQ

 

Share this post


Link to post
Share on other sites

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
Sign in to follow this  
Followers 0