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 

Documentation Suggestion (FileAppend/STDOUT)

 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List
View previous topic :: View next topic  
Author Message
JBensimon



Joined: 16 Nov 2004
Posts: 130
Location: New York

PostPosted: Fri Dec 29, 2006 6:48 am    Post subject: Documentation Suggestion (FileAppend/STDOUT) Reply with quote

Needed to output some info to the console, so I finally got around to reading the following in the FileAppend documentation page:
Quote:
Specifying an asterisk (*) for Filename causes Text to be sent to standard output (stdout) [...] However, text sent to stdout will not appear at the command prompt it was launched from. This can be worked around by downloading a utility such as PipeSplit.exe (8 KB) and using a command line such as the following:
Code:
"%ProgramFiles%\AutoHotkey\AutoHotkey.exe" "My Script.ahk" |PipeSplit.exe nul

I thought I'd point out that a "native" way to see text sent to stdout is to instead use a line like
Code:
For /F "tokens=*" %L in ('"%ProgramFiles%\AutoHotkey\AutoHotkey.exe" "My Script.ahk"') do @Echo %L

Of course, for casual viewing of the output, you could also use
Code:
"%ProgramFiles%\AutoHotkey\AutoHotkey.exe" "My Script.ahk" | More

Jacques.
Back to top
View user's profile Send private message Visit poster's website
PhiLho



Joined: 27 Dec 2005
Posts: 6702
Location: France (near Paris)

PostPosted: Fri Dec 29, 2006 10:15 am    Post subject: Reply with quote

Additional info: Return for the script itself
_________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")
Back to top
View user's profile Send private message Visit poster's website
JBensimon



Joined: 16 Nov 2004
Posts: 130
Location: New York

PostPosted: Fri Dec 29, 2006 5:59 pm    Post subject: Reply with quote

I like your code for reading from StdIn. Makes it possible to write filters with AHK. (J'aime les pipes ! Wink)

Thanks,

Jacques.
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10450

PostPosted: Sat Dec 30, 2006 3:14 pm    Post subject: Re: Documentation Suggestion (FileAppend/STDOUT) Reply with quote

JBensimon wrote:
a "native" way to see text sent to stdout is to instead use a line like
Code:
For /F "tokens=*" %L in ('"%ProgramFiles%\AutoHotkey\AutoHotkey.exe" "My Script.ahk"') do @Echo %L
I couldn't get that to work. It says, 'C:\Program' is not recognized as an internal or external command....

JBensimon wrote:
for casual viewing of the output, you could also use
Code:
"%ProgramFiles%\AutoHotkey\AutoHotkey.exe" "My Script.ahk" | More
Nice tip. I'll probably add this to the documentation, and would like to add the for/echo method too if it can be made to work with long filenames.

Thanks.
Back to top
View user's profile Send private message Send e-mail
Laszlo



Joined: 14 Feb 2005
Posts: 3877
Location: Pittsburgh

PostPosted: Sat Dec 30, 2006 5:35 pm    Post subject: Re: Documentation Suggestion (FileAppend/STDOUT) Reply with quote

Chris wrote:
I couldn't get that to work. It says, 'C:\Program' is not recognized as an internal or external command...
Just one more set of quotes (xxx.ahk is the script with its full path):
Code:
C:\>For /F "tokens=*" %L in ('""%ProgramFiles%\AutoHotkey\AutoHotkey.exe" "xxx.ahk""') do @Echo %L

If you are in the right directory, you can drop the path:
Code:
C:\t\AutoHotKey>For /F %L in ('""%ProgramFiles%\AutoHotkey\AutoHotkey.exe" "test.ahk""') do @Echo %L


Last edited by Laszlo on Sat Dec 30, 2006 6:08 pm; edited 2 times in total
Back to top
View user's profile Send private message Visit poster's website
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10450

PostPosted: Sat Dec 30, 2006 5:41 pm    Post subject: Reply with quote

Thanks.
Back to top
View user's profile Send private message Send e-mail
Guest






PostPosted: Sat Dec 30, 2006 11:51 pm    Post subject: Reply with quote

It may not have been very clear in my original post because of the way single and double quotes are drawn, but when using "For /F" to process the output of a command, the entire command and its parameters (along with any double-quotes they may require because of long pathnames) are placed together in a set of *single* quotes inside the parentheses, like so

For /F "parsing rules" %L in ('command') do ...

Jacques.
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10450

PostPosted: Sun Dec 31, 2006 12:09 am    Post subject: Reply with quote

Right, but it looks like three sets of quotes are needed for some reason (one single-quote set and two double-quote sets).

I've added the following examples to the FileAppend page:
Quote:
...text sent to stdout will not appear at the command prompt it was launched from. This can be worked around by piping a script's output to another command or program. For example:
1) "%ProgramFiles%\AutoHotkey\AutoHotkey.exe" "My Script.ahk" |more
2) For /F "tokens=*" %L in ('""%ProgramFiles%\AutoHotkey\AutoHotkey.exe" "My Script .ahk""') do @Echo %L
Thanks again for the improvement.
Back to top
View user's profile Send private message Send e-mail
JBensimon



Joined: 16 Nov 2004
Posts: 130
Location: New York

PostPosted: Sun Dec 31, 2006 12:35 am    Post subject: Reply with quote

You (and Laszlo) are quite right empirically about the need for the extra double-quotes when the executable in the command is itself in double-quotes, but this can't be explained by the "For /F" syntax rules. Must be a quirk (i.e. bug Smile) in the way the For command is parsed. I'd have known this if I didn't install AutoHotkey in C:\AutoHotkey! Smile

Thanks,

Jacques.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Wish List 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