Sends any syntax error that prevents a script from launching to the standard error stream (stderr) rather than displaying a dialog.
#ErrorStdOut Encoding
#ErrorStdOut UTF-8
encodes error messages as UTF-8 before sending them to stderr. Whatever program is capturing the output must support UTF-8, and in some cases may need to be configured to expect it. If omitted, it defaults to CP0.[AHK_L 42+]: Errors are written to stderr instead of stdout. The command prompt and fancy editors usually display both. This change was undocumented until after [v1.1.19.01].
This allows fancy editors such as TextPad, SciTE, Crimson, and EditPlus to jump to the offending line when a syntax error occurs. Since the #ErrorStdOut directive would have to be added to every script, it is usually better to set up your editor to use the command line switch /ErrorStdOut when launching any AutoHotkey script (see further below for setup instructions).
Because AutoHotkey is not a console program, errors will not appear at the command prompt directly. This can be worked around by 1) [v1.1.33+] compiling the script with the Ahk2Exe ConsoleApp directive, or 2) capturing the script's output via piping or redirection. For example:
"C:\Program Files\AutoHotkey\AutoHotkey.exe" /ErrorStdOut "My Script.ahk" 2>&1 |more "C:\Program Files\AutoHotkey\AutoHotkey.exe" /ErrorStdOut "My Script.ahk" 2>"Syntax-Error Log.txt"
You can also pipe the output directly to the clipboard by using the operating system's built-in clip command (for Windows XP and lower, download and use cb.exe instead). For example:
"C:\Program Files\AutoHotkey\AutoHotkey.exe" /ErrorStdOut "My Script.ahk" 2>&1 |clip
Note: 2>&1
causes stderr to be redirected to stdout, while 2>Filename
redirects only stderr to a file.
Like other directives, #ErrorStdOut cannot be executed conditionally.
EditPlus:
C:\Program Files\AutoHotkey\AutoHotkey.exe
/ErrorStdOut "$(FilePath)"
$(FileDir)
TextPad:
C:\Windows\System32\cmd.exe
-- then press OK.cmd.exe
(or the full path to it)/c ""C:\Program Files\AutoHotkey\AutoHotkey.exe" /ErrorStdOut "$File""
$FileDir
FileAppend (because it can also send text to stderr or stdout)