Code: Select all
;FileAppend, % vOutput, *, UTF-8
FileAppend, % vOutput, **, UTF-8
;FileAppend, % vOutput, * *, UTF-8 ;doesn't work
;FileAppend, % vOutput, * **, UTF-8 ;doesn't work
;FileAppend, % vOutput, %vPath%, UTF-8
;FileAppend, % vOutput, * %vPath%, UTF-8
- Also, if they don't work, then the lines using the vPath variable are less versatile, and cannot accept * or **.
- There is a further problem, either ** always appends to StdOut (it should append to StrErr), or, the retrieve StdErr function below doesn't work (and it always retrieves the StdOut).
- Script 1: Retrieve text.
Code: Select all
;FileAppend
;https://autohotkey.com/docs/commands/FileAppend.htm
q:: ;test append stdout+stderr
vPath := A_Desktop "\test append stdout+stderr.ahk"
vTarget = "%A_AhkPath%" "%vPath%"
MsgBox, % JEE_RunGetStdOut(vTarget)
MsgBox, % JEE_RunGetStdErr(vTarget)
;MsgBox, % StrLen(JEE_RunGetStdOut(vTarget))
;MsgBox, % StrLen(JEE_RunGetStdErr(vTarget))
return
;==================================================
;JEE_RunWaitGetStdOut
JEE_RunGetStdOut(vTarget, vSize:="")
{
DetectHiddenWindows, On
vComSpec := A_ComSpec ? A_ComSpec : ComSpec
Run, % vComSpec,, Hide, vPID
WinWait, % "ahk_pid " vPID
DllCall("kernel32\AttachConsole", UInt,vPID)
oShell := ComObjCreate("WScript.Shell")
oExec := oShell.Exec(vTarget)
vStdOut := ""
if !(vSize = "")
VarSetCapacity(vStdOut, vSize)
while !oExec.StdOut.AtEndOfStream
vStdOut := oExec.StdOut.ReadAll()
DllCall("kernel32\FreeConsole")
Process, Close, % vPID
return vStdOut
}
;==================================================
;JEE_RunWaitGetStdErr
JEE_RunGetStdErr(vTarget, vSize:="")
{
DetectHiddenWindows, On
vComSpec := A_ComSpec ? A_ComSpec : ComSpec
Run, % vComSpec,, Hide, vPID
WinWait, % "ahk_pid " vPID
DllCall("kernel32\AttachConsole", UInt,vPID)
oShell := ComObjCreate("WScript.Shell")
oExec := oShell.Exec(vTarget)
vStdErr := ""
if !(vSize = "")
VarSetCapacity(vStdErr, vSize)
while !oExec.StdErr.AtEndOfStream
vStdErr := oExec.StdErr.ReadAll()
DllCall("kernel32\FreeConsole")
Process, Close, % vPID
return vStdErr
}
;==================================================
Code: Select all
vOutput := "a`r`nb`r`nc`r`nd`r`ne" ;length 13
;vOutput := "a`r`n" Chr(8730) "`r`nc"
;vOutput := "a`nb`nc`nd`ne" ;length 9
;FileAppend, % vOutput, *, UTF-8
FileAppend, % vOutput, **, UTF-8
;FileAppend, % vOutput, * *, UTF-8
;FileAppend, % vOutput, * **, UTF-8