AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Can a script write to STDERR?

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
wtg



Joined: 04 Oct 2006
Posts: 210
Location: Louisville, KY

PostPosted: Fri Feb 12, 2010 7:07 pm    Post subject: Can a script write to STDERR? Reply with quote

It's easy enough to write to STDOUT, but I can't find a way to write a message STDERR. Am I overlooking something?
Back to top
View user's profile Send private message
OceanMachine



Joined: 15 Oct 2007
Posts: 780
Location: England

PostPosted: Fri Feb 12, 2010 7:11 pm    Post subject: Reply with quote

OutputDebug? - I think this is what you want.

#ErrorStdOut?

Not sure if any of these help you Laughing

Redirect stdin, stdout and stderr [GUI]

Also, check this thread out:

fincs wrote:
some modifications were done by me in order to support them (FileAppend Asterisk->stdout, OutputDebug->stderr and runtime error messages->stderr are supported).
Back to top
View user's profile Send private message
wtg



Joined: 04 Oct 2006
Posts: 210
Location: Louisville, KY

PostPosted: Fri Feb 12, 2010 9:17 pm    Post subject: Reply with quote

Thanks OceanMachine, but unfortunately OutputDebug doesn't work. It's interesting that the #ErrorStdOut parm lets us redirect STDERR to STDOUT, but we don't actually have a way to write to STDERR that I can find.

Regarding the fincs thread, if I understand it correctly, he's made some modifications to the _L release so OutputDebug will output to STDERR that can then be used by SciTE debugger.

Oh well... it's not that important. I was just trying to test another apps use handling of STDOUT and STDERR and thought I could write something in Autohotkey to output to both quickly. Guess I was wrong... Smile

Thanks anyway!
Back to top
View user's profile Send private message
OceanMachine



Joined: 15 Oct 2007
Posts: 780
Location: England

PostPosted: Sat Feb 13, 2010 12:54 am    Post subject: Reply with quote

Hmm OK, sorry.

I use OutputDebug with Debug Viewer, and I get debug messages appearing from other programs running on my computer at work (McAfee, etc) while I am monitoring it for my AHK scripts, so I thought that you might be able to debug your other code (along with autohotkey) using Debug Viewer. Maybe not Sad

Sorry I couldn't help more... maybe someone else knows of a way?
Back to top
View user's profile Send private message
Lexikos



Joined: 17 Oct 2006
Posts: 7295
Location: Australia

PostPosted: Sat Feb 13, 2010 4:01 am    Post subject: Reply with quote

OceanMachine wrote:
OutputDebug?
OutputDebug outputs to a debugger via OutputDebugString if one is attached to the current process. Tools like DbgView can catch it, as can Visual Studio if you're debugging AutoHotkey.exe (useful only to developers like myself). It doesn't output to stderr.
wtg wrote:
It's interesting that the #ErrorStdOut parm lets us redirect STDERR to STDOUT,
Don't be misled by the name; it has nothing to do with stderr:
Quote:
Sends any syntax error that prevents a script from launching to stdout rather than displaying a dialog.
Source: #ErrorStdOut

Quote:
Regarding the fincs thread, if I understand it correctly, he's made some modifications to the _L release so OutputDebug will output to STDERR that can then be used by SciTE debugger.
fincs statement is easily misinterpreted. He was referring specifically to the "stderr" DBGp command, which is ordinarily intended for redirecting the stderr stream to a DBGp (debugger) client. In our case, AutoHotkey doesn't make use of the stderr stream, so fincs repurposed the "stderr" command for redirecting OutputDebug to the DBGP client. The actual stderr stream is not involved.

Try this:
Code:
StdErr_Write("hello, world!")
StdErr_Write(text) {
    if A_IsUnicode
        ; Note: StrLen(text) might be incorrect if multi-byte characters are involved:
        return StdErr_Write_("astr", text, StrLen(text))
    return StdErr_Write_("uint", &text, StrLen(text))
}
StdErr_Write_(type, data, size) {
    static STD_ERROR_HANDLE := -12
    if (hstderr := DllCall("GetStdHandle", "uint", STD_ERROR_HANDLE)) = -1
        return false
    return DllCall("WriteFile", "uint", hstderr, type, data, "uint", size, "uint", 0, "uint", 0)
}
Back to top
View user's profile Send private message Visit poster's website
wtg



Joined: 04 Oct 2006
Posts: 210
Location: Louisville, KY

PostPosted: Sun Feb 14, 2010 9:49 pm    Post subject: Reply with quote

Lexikos wrote:

wtg wrote:
It's interesting that the #ErrorStdOut parm lets us redirect STDERR to STDOUT,
Don't be misled by the name; it has nothing to do with stderr:
Quote:
Sends any syntax error that prevents a script from launching to stdout rather than displaying a dialog.
Source: #ErrorStdOut


Of course... I noticed that when I first read the help - that it really simply redirected the output that is normally to a dialog - and then forgot it by the time I was posting. Thanks for the clarification.
Lexikos wrote:

Try this:
Code:
StdErr_Write("hello, world!")
StdErr_Write(text) {
    if A_IsUnicode
        ; Note: StrLen(text) might be incorrect if multi-byte characters are involved:
        return StdErr_Write_("astr", text, StrLen(text))
    return StdErr_Write_("uint", &text, StrLen(text))
}
StdErr_Write_(type, data, size) {
    static STD_ERROR_HANDLE := -12
    if (hstderr := DllCall("GetStdHandle", "uint", STD_ERROR_HANDLE)) = -1
        return false
    return DllCall("WriteFile", "uint", hstderr, type, data, "uint", size, "uint", 0, "uint", 0)
}

Works great! Thanks Lexikos!
Back to top
View user's profile Send private message
amnesiac



Joined: 07 Nov 2010
Posts: 41
Location: Egret Island

PostPosted: Mon Jun 06, 2011 7:18 am    Post subject: Reply with quote

I think using WshShell Object maybe a better way. For details, please see:
[AHK&AHK_l]Using COM to interact with command-line progs
_________________
For Chinese users, please visit AutoHotkey Chinese Site
Together with AutoHotkey, we grow and march forward. No matter how the future will be, this period of days is still epic.
Back to top
View user's profile Send private message Send e-mail MSN Messenger
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group