| View previous topic :: View next topic |
| Author |
Message |
JBensimon
Joined: 16 Nov 2004 Posts: 130 Location: New York
|
Posted: Fri Dec 29, 2006 6:48 am Post subject: Documentation Suggestion (FileAppend/STDOUT) |
|
|
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 |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6702 Location: France (near Paris)
|
Posted: Fri Dec 29, 2006 10:15 am Post subject: |
|
|
Additional info: Return for the script itself _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
JBensimon
Joined: 16 Nov 2004 Posts: 130 Location: New York
|
Posted: Fri Dec 29, 2006 5:59 pm Post subject: |
|
|
I like your code for reading from StdIn. Makes it possible to write filters with AHK. (J'aime les pipes ! )
Thanks,
Jacques. |
|
| Back to top |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10450
|
Posted: Sat Dec 30, 2006 3:14 pm Post subject: Re: Documentation Suggestion (FileAppend/STDOUT) |
|
|
| 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 |
|
 |
Laszlo
Joined: 14 Feb 2005 Posts: 3877 Location: Pittsburgh
|
Posted: Sat Dec 30, 2006 5:35 pm Post subject: Re: Documentation Suggestion (FileAppend/STDOUT) |
|
|
| 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 |
|
 |
Chris Site Admin
Joined: 02 Mar 2004 Posts: 10450
|
Posted: Sat Dec 30, 2006 5:41 pm Post subject: |
|
|
| Thanks. |
|
| Back to top |
|
 |
Guest
|
Posted: Sat Dec 30, 2006 11:51 pm Post subject: |
|
|
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
|
Posted: Sun Dec 31, 2006 12:09 am Post subject: |
|
|
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 |
|
 |
JBensimon
Joined: 16 Nov 2004 Posts: 130 Location: New York
|
Posted: Sun Dec 31, 2006 12:35 am Post subject: |
|
|
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 ) in the way the For command is parsed. I'd have known this if I didn't install AutoHotkey in C:\AutoHotkey!
Thanks,
Jacques. |
|
| Back to top |
|
 |
|