[FUNCTION] StdoutToVar with exit code

Post your working scripts, libraries and tools
User avatar
cyruz
Posts: 244
Joined: 30 Sep 2013, 13:31

[FUNCTION] StdoutToVar with exit code

27 Nov 2013, 17:10

Hi guys, this is the same function brought to us by Sean and modified by nfl for compatibility with AutoHotkey_L with the addition of the exit code, returned as a byref parameter.

Code: [Select all] [Expand] [Download] (StdoutToVar.ahk)GeSHi © Codebox Plus

Last edited by cyruz on 02 Nov 2016, 04:02, edited 11 times in total.
ABCza on the old forum.
My GitHub.
wzxiaodu
Posts: 10
Joined: 30 Nov 2013, 09:42

Re: [FUNCTION] StdoutToVar with exit code

30 Nov 2013, 09:51

StdoutToVar_CreateProcess("ping www.sina.com.cn")
;;;;;;;;(my english is poor! sorry!)

result :
???? Ping auriga.sina.com.cn [61.172.201.194] ???? 32 ????????:
???? 61.172.201.194 ????: ???=32 ???=13ms TTL=247
???? 61.172.201.194 ????: ???=32 ???=13ms TTL=247
???? 61.172.201.194 ????: ???=32 ???=13ms TTL=247
???? 61.172.201.194 ????: ???=32 ???=12ms TTL=247

61.172.201.194 ?? Ping ??????:
?????: ????? = 4??????? = 4????? = 0 (0% ???)??
?????г????????(????????λ):
??? = 12ms???? = 13ms????? = 12ms
User avatar
cyruz
Posts: 244
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] StdoutToVar with exit code

30 Nov 2013, 15:00

Hi wzxiaodu,
it works for me. Maybe you used AutoHotkey ANSI?
ABCza on the old forum.
My GitHub.
wzxiaodu
Posts: 10
Joined: 30 Nov 2013, 09:42

Re: [FUNCTION] StdoutToVar with exit code

01 Dec 2013, 01:10

111.png

222.PNG
222.PNG (25.23 KiB) Viewed 5468 times
wzxiaodu
Posts: 10
Joined: 30 Nov 2013, 09:42

Re: [FUNCTION] StdoutToVar with exit code

01 Dec 2013, 08:46

it can use on OSx32
not good on OSx64 !!
User avatar
cyruz
Posts: 244
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] StdoutToVar with exit code

01 Dec 2013, 14:52

wzxiaodu wrote:it can use on OSx32
not good on OSx64 !!


I will look into it. Until now I just reformatted the code and added the exit code feature.
Thanks for the bug report :)
ABCza on the old forum.
My GitHub.
User avatar
cyruz
Posts: 244
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] StdoutToVar with exit code

07 Dec 2013, 08:54

wzxiaodu can you try now? There was an error with the 64 bit size of the STARTUPINFO structure.
ABCza on the old forum.
My GitHub.
User avatar
cyruz
Posts: 244
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] StdoutToVar with exit code

09 Dec 2013, 09:41

wzxiaodu wrote:
222.PNG


I see. I updated the code a little, but I don't think it will solve your problem. I tried with AHK x64 and it works for me, so maybe the problem is related to the string concatenation code. We need the help of a Unicode master...
ABCza on the old forum.
My GitHub.
artlotz
Posts: 1
Joined: 20 Dec 2013, 19:23

Re: [FUNCTION] StdoutToVar with exit code

20 Dec 2013, 20:32

line number 45, sOutput := sOutput . StrGet(&sTemp, nSize, "UTF-8") <- I guess this a part is to change like under

sOutput := sOutput . StrGet(&sTemp, nSize, "your codepage") codepages may perhaps assume as cp936 or cp950...

see msdn : http://msdn.microsoft.com/en-us/library/dd317756.aspx
User avatar
cyruz
Posts: 244
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] StdoutToVar with exit code

27 Dec 2013, 14:54

wnltl wrote:line number 45, sOutput := sOutput . StrGet(&sTemp, nSize, "UTF-8") <- I guess this a part is to change like under

sOutput := sOutput . StrGet(&sTemp, nSize, "your codepage") codepages may perhaps assume as cp936 or cp950...

see msdn : http://msdn.microsoft.com/en-us/library/dd317756.aspx


Isn't Unicode supposed to replace all this codepages? Are you sure this could be the problem?

@wzxiaodu: if you can check it!
ABCza on the old forum.
My GitHub.
magusneo
Posts: 23
Joined: 30 Sep 2013, 06:34

Re: [FUNCTION] StdoutToVar with exit code

23 Feb 2014, 09:08

replace ""UTF-8"" as A_FileEncoding works under chinese win7 64.
User avatar
cyruz
Posts: 244
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] StdoutToVar with exit code

23 Feb 2014, 11:35

magusneo wrote:replace ""UTF-8"" as A_FileEncoding works under chinese win7 64.


Nice, I'll update.
ABCza on the old forum.
My GitHub.
User avatar
cyruz
Posts: 244
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] StdoutToVar with exit code

09 Mar 2014, 12:53

Code updated, removed input feature.
ABCza on the old forum.
My GitHub.
lexikos
Posts: 5896
Joined: 30 Sep 2013, 04:07
GitHub: Lexikos

Re: [FUNCTION] StdoutToVar with exit code

14 Mar 2014, 20:58

FYI, there's no single solution for decoding the output of a process, since a process can output in whatever encoding it wants. Programs can (but mostly don't, I think) set the codepage used by the console, and can output UTF-16 directly to the console, but neither works with redirected output (like this script).

I think mostly programs (especially ones which use C runtime functions like printf) just output in the system's default ANSI codepage, which happens to be the default for A_FileEncoding. However, if the script changes the default file encoding, it will fail. It would be better for the script to specify (as a parameter) the codepage that it expects the program to output, and default to "cp0".
User avatar
cyruz
Posts: 244
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] StdoutToVar with exit code

15 Mar 2014, 19:54

lexikos wrote:FYI, there's no single solution for decoding the output of a process, since a process can output in whatever encoding it wants. Programs can (but mostly don't, I think) set the codepage used by the console, and can output UTF-16 directly to the console, but neither works with redirected output (like this script).

I think mostly programs (especially ones which use C runtime functions like printf) just output in the system's default ANSI codepage, which happens to be the default for A_FileEncoding. However, if the script changes the default file encoding, it will fail. It would be better for the script to specify (as a parameter) the codepage that it expects the program to output, and default to "cp0".


Thank you lexikos. This encoding/codepage stuff has always been difficult for me. I will update the script with your suggestion soon.
ABCza on the old forum.
My GitHub.
User avatar
cyruz
Posts: 244
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] StdoutToVar with exit code

16 Mar 2014, 12:48

Updated with lexikos suggestion.
ABCza on the old forum.
My GitHub.
User avatar
cyruz
Posts: 244
Joined: 30 Sep 2013, 13:31

Re: [FUNCTION] StdoutToVar with exit code

02 Jun 2014, 05:11

Corrected an error related to the exit code.
ABCza on the old forum.
My GitHub.
Cubex
Posts: 4
Joined: 06 Sep 2014, 06:23

Re: [FUNCTION] StdoutToVar with exit code

06 Sep 2014, 06:38

wzxiaodu wrote:StdoutToVar_CreateProcess("ping http://www.sina.com.cn")
;;;;;;;;(my english is poor! sorry!)

result :
???? Ping auriga.sina.com.cn [61.172.201.194] ???? 32 ????????:
???? 61.172.201.194 ????: ???=32 ???=13ms TTL=247
???? 61.172.201.194 ????: ???=32 ???=13ms TTL=247
???? 61.172.201.194 ????: ???=32 ???=13ms TTL=247
???? 61.172.201.194 ????: ???=32 ???=12ms TTL=247

61.172.201.194 ?? Ping ??????:
?????: ????? = 4??????? = 4????? = 0 (0% ???)??
?????г????????(????????λ):
??? = 12ms???? = 13ms????? = 12ms


Hi wzxiaodu,
I have "Win7 32bit czech" and helped me:
StdoutToVar_CreateProcess(sCmd, sEncoding:="CP1", sDir:="", ByRef nExitCode:=0){
.....
You try it.
Ajdaha
Posts: 1
Joined: 19 Dec 2014, 19:26

Re: [FUNCTION] StdoutToVar with exit code

19 Dec 2014, 20:01

Hi and thanks for this usefull function.

I just want to know is there a way to this function runs process with admin privilages? (I don't want to run my entire script as admin!)

I mean something like this "Run *RunAs ..." happen inside of the function!
(I'm genius and I know it! :v)

Return to “Scripts and Functions”

Who is online

Users browsing this forum: arcticir, kunkel321 and 10 guests