#ErrorStdOut

Auto Hotkey

#ErrorStdOut

Sends any syntax error that prevents a script from launching to stderr rather than displaying a dialog.

#ErrorStdOut

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. Instead, such output can be captured 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 downloading cb.zip (4 KB) and then following this example:

"C:\Program Files\AutoHotkey\AutoHotkey.exe" /ErrorStdOut "My Script.ahk" 2>&1 |cb.exe

Note: 2>&1 causes stderr to be redirected to stdout, while 2>Filename redirects only stderr to a file.

Instructions for specific editors

EditPlus:
From the menu bar, select Tools > Configure User Tools.
Press button: Add Tool > Program
Menu Text: Your choice
Command: C:\Program Files\AutoHotkey\AutoHotkey.exe
Argument: /ErrorStdOut "$(FilePath)"
Initial directory: $(FileDir)
Capture output: Yes

TextPad:
From the menu bar, select Configure > Preferences.
Expand the Tools entry.
Press the Add button and select "Program".
Copy and paste (adjust to your path): C:\Windows\System32\cmd.exe -- then press OK.
Triple-click the newly added item (cmd.exe) in the ListBox and rename it to your choice (e.g. Launch Script).
Press Apply.
Select the new item in the tree at the left and enter the following information:
Command (should already be filled in): cmd.exe (or the full path to it)
Parameters (adjust to your path, if necessary): /c ""C:\Program Files\AutoHotkey\AutoHotkey.exe" /ErrorStdOut "$File""
Initial folder: $FileDir
Check the following boxes: 1) Run minimized; 2) Capture output.
Press OK. The newly added item should now exist in the Tools menu.

Related

FileAppend (because it can also send text to stdout)

Example

#ErrorStdOut