ProgramFiles variable | Type(A_LastError) | ProcessWaitClose Timeout | Run Return value

Discuss the future of the AutoHotkey language
User avatar
Flipeador
Posts: 1146
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

ProgramFiles variable | Type(A_LastError) | ProcessWaitClose Timeout | Run Return value

27 Apr 2019, 18:59

ProgramFiles variable:

Code: Select all

MsgBox(ProgramFiles . "`n" . A_Desktop)  ; A_Desktop `n A_Desktop  ???
Type(A_LastError):

Code: Select all

MsgBox(Type(A_LastError))  ; Is not it supposed to be an unsigned integer?
ProcessWaitClose Timeout:

Code: Select all

; Timeout:
; If BLANK or omitted, this function will wait indefinitely.
Run("mspaint.exe",,, pid)
MsgBox(ProcessWaitClose(pid, ""),,0x1000)  ; ??
MsgBox(ProcessWaitClose(pid),,0x1000)
Run - Return value:

Code: Select all

MsgBox(Run("mspaint.exe"))  ; What is the return value of the Run function?. It could return the PID.
:wave:
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina
(If any of my code written for v2 has stopped working, send me a private message. I appreciate that you correct my English.)
Helgef
Posts: 3981
Joined: 17 Jul 2016, 01:02
Contact:

Re: ProgramFiles variable | Type(A_LastError) | ProcessWaitClose Timeout | Run Return value

29 Apr 2019, 01:29

Hi Flipeador :wave:
ProgramFiles
Is there an issue? ProgramFiles is not a built in variable and is blank on a100 for me. You can use A_ProgramFiles.
Type(A_LastError): ; Is not it supposed to be an unsigned integer?
The names of pure number types of values stored in AHK variables are Integer and Float. The fact that the above returns string is due to limitations of the built in var implementation, that is, you get a numeric string.
; What is the return value of the Run function?
It has none.

Cheers.
lexikos
Posts: 6652
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: ProgramFiles variable | Type(A_LastError) | ProcessWaitClose Timeout | Run Return value

29 Apr 2019, 02:01

For Run, there are two reasons I have not shifted the OutputVarPID to the return value:
  • RunWait returns the exit code but also has OutputVarPID. (But Batch uses ErrorLevel for the exit code, and that's probably the origin of our ErrorLevel...)
  • I consider having Run return something like WScript.Shell.Exec, for stdout/stderr/stdin and perhaps other things. I also consider making that a different function (since it is probably no good to redirect the std streams by default), but haven't decided on a name.
User avatar
Flipeador
Posts: 1146
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: ProgramFiles variable | Type(A_LastError) | ProcessWaitClose Timeout | Run Return value

29 Apr 2019, 08:15

Is there an issue? ProgramFiles is not a built in variable and is blank on a100 for me.
I know, but for some strange reason it's not blank for me. It shows me the same as A_Desktop (2.0-a100-52515e2). :shock:
The names of pure number types of values stored in AHK variables are Integer and Float. The fact that...
It seems then that ErrorLevel behaves differently to the A_ variables.

I consider having Run return something like WScript.Shell.Exec... I also consider making that a different function...
Sounds good, although I don't see how having this built-in can be more beneficial than a library written purely in .ahk.

:wave:
Windws 1♂ Pro 64-Bits I make scripts for AHKv2 (my v2 compiler) & WIN_7+ Spanish Argentina
(If any of my code written for v2 has stopped working, send me a private message. I appreciate that you correct my English.)
Helgef
Posts: 3981
Joined: 17 Jul 2016, 01:02
Contact:

Re: ProgramFiles variable | Type(A_LastError) | ProcessWaitClose Timeout | Run Return value

29 Apr 2019, 08:46

I know, but for some strange reason it's not blank for me. It shows me the same as A_Desktop
I see the same on the 32 bit build but not on 64 bit. :thumbsup:

Errorlevel is different. Some a_ variables are worked around to return pure integer, eg, a_index

Cheers.
lexikos
Posts: 6652
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: ProgramFiles variable | Type(A_LastError) | ProcessWaitClose Timeout | Run Return value

30 Apr 2019, 07:54

ErrorLevel is basically an ordinary super-global variable.

ProgramFiles was partially reintroduced by accident when commit 019ab94d was merged into the alpha branch by commit b9b520a9. Prior to these commits, built-in variables were resolved by a very long if-else-if ladder. This was replaced by a table of variables, and when this table was merged into alpha, the ProgramFiles variable was erroneously left in.

However, its value is indeterminate; it may either be blank or the value of an arbitrary folder returned by SHGetFolderPath.
lexikos
Posts: 6652
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: ProgramFiles variable | Type(A_LastError) | ProcessWaitClose Timeout | Run Return value

09 May 2019, 22:48

v2.0-a101 fixes ProgramFiles (by removing it again).

For ProcessWait, the documentation is incorrect - "blank or" is left over from when it was a command. Commands treated omitted and blank parameters as the same thing, since they generally were the same thing (because quote marks were not required). You should note that the v2 documentation indicates the Timeout parameter has "Type: Integer or Float". "" is neither of those.

A_LastError will be fixed when the built-in variable mechanism is revised. Until then, it does not seem worth making an exception for this variable; unlike A_ScriptHwnd and some others, there doesn't seem to be any reason that the type of A_LastError would matter.

Also, it seems that the documentation does not specify the type of value returned by any built-in variable.
User avatar
Flipeador
Posts: 1146
Joined: 15 Nov 2014, 21:31
GitHub: Flipeador
Location: Argentina
Contact:

Re: ProgramFiles variable | Type(A_LastError) | ProcessWaitClose Timeout | Run Return value

10 Jul 2019, 19:27

With respect to A_LastError, not only is the data type wrong, but the value returned is too:

Code: Select all

A_LastError := 4294967295
MsgBox  A_LastError                                   ; -1         - ??.
MsgBox  DllCall("Kernel32.dll\GetLastError", "UInt")  ; 4294967295 - OK.
A_LastError⠀ wrote:Read/write: [...] A_LastError is a number between 0 and 4294967295 [...]
https://lexikos.github.io/v2/docs/Variables.htm#LastError
The type of data returned by this variable may not matter in most scenarios, but it is not correct, period. Of course it also applies to other variables.

There are also several functions that return an empty string, instead of zero, I hope this will be changed (WinGetPID, ControlGetHwnd, WinGetControlsHwnd, etc.). I think zero is more appropriate to indicate an error, especially if ""=TRUE is planned.

Return to “AutoHotkey v2 Development”

Who is online

Users browsing this forum: No registered users and 9 guests