AutoHotkey Community

It is currently May 27th, 2012, 10:18 am

All times are UTC [ DST ]




Post new topic Reply to topic  [ 13 posts ] 
Author Message
PostPosted: June 17th, 2007, 6:07 pm 
Offline

Joined: July 5th, 2006, 6:22 am
Posts: 37
I'm working on a script that's intended to be run from a command prompt, and I'd like to be able to report status messages to the command prompt the script was run from.

As I understand it, I'd do this by using FileAppend and sending the output to an * instead of an actual file. However, I read this section in the help file under FileAppend:

"However, 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"

Has anyone figured out a way around this?

In case I'm not clear, I'd like to, for example, report a program's successful execution back to the command prompt. For example if this was the contents of test.ahk:

if (success = "yes")
{
FileAppend,
(
executed successfully
), *

}

Executing it at a command prompt would look like this:

C:\> test.ahk
executed successfully

C:\>


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 17th, 2007, 9:14 pm 
Well, assuming you have the StdOut into a variable, ("VariableHere") in this case
Code:
VariableHere = Blah Blah Blah Blah

TempFile = %A_Temp%\TempDat.bat
FileAppend,
(
Echo Off
Cls
Prompt $G:
Echo %VariableHere%
Pause
), %TempFile%
RunWait %TempFile%
FileDelete %TempFile%


Tested.


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: June 17th, 2007, 11:14 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8667
Location: Salem, MA
you probably want to remove the prompt command, and change Echo Off to @Echo off if you are going to do it this way.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 20th, 2007, 11:38 pm 
Oh stfu it works fine lol


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2008, 12:03 pm 
Offline

Joined: June 14th, 2005, 10:47 am
Posts: 28
Sorry, but doesnt work for me.

If I put exact the same lines from above into a ahk script neither starting this script nor the comiled exe gives the output into the same dos box, where I startet it.
Always a new dos box pops up:-(

Image
...any idea someone what I'm doing wrong ?
(thanks)

copa

--------------------------
WinXp Pro, German
AHK 1.0.47.06


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 16th, 2008, 5:17 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8667
Location: Salem, MA
the documentation states:
Quote:
text sent to stdout will not appear at the command prompt it was launched from


The script above was designed to open a new dos window, so it will.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2008, 8:39 am 
Offline

Joined: June 14th, 2005, 10:47 am
Posts: 28
ups, but many thanks for your reply !

I thought while reading the TO
Quote:
C:\> test.ahk
executed successfully

C:\>

that there was a need for command line output in the same dos box.

Ok, then: How can I produce output in the same dos box ?
(I'm really sorry, if this question is somehow stupid...)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2008, 8:50 am 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
instead of run try
Code:
Send, %TempFile%{Enter}
it will run the batch file in the current console window (run will start a new one)

You might be interested in this script by Lexikos
http://www.autohotkey.com/forum/viewtop ... 921#180719

and this one, Console application with ahk
http://www.autohotkey.com/forum/topic30759.html


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2008, 11:06 am 
Offline

Joined: June 14th, 2005, 10:47 am
Posts: 28
HugoV, thanks for your effort, but no luck on my side...


Quote:
instead of run try

Send, %TempFile%{Enter}
it will run the batch file in the current console window (run will start a new one)


Doesnt work since the dos box where the script is started is waiting actually for the script to finish until it accepts new input

And the other 2 links are interesting, but they both cover scripts that open another dos box for user input/output.


BTW If someone is interested what I need this for: Its for writing a so called "hook" for Subversion (SVN, a sw sources versioning repository similar to CVS).
The result of the server-side running "hook" needs to be returned by stdout so the user can read it then on its SVN client..


Last edited by copa_ahk on July 17th, 2008, 12:34 pm, edited 1 time in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2008, 12:27 pm 
Offline

Joined: May 27th, 2007, 9:41 am
Posts: 4999
If there is a way to check with AHK if it is ready before you use send that should work. The purpose of the other two is that you run the application within those scripts so you can monitor feedback more easily e.g. you now start a batch process and THEN you want to do something with AHK. Start the AHK first, which runs the first batch and THEN your second batch etc all from with the console created by your AHK. (if that makes any sense). Perhaps CMDret (search the forum) is something you might want to look into.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 17th, 2008, 4:25 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8667
Location: Salem, MA
Even though you cannot read it in the dos window, another program calling your exe and reading the output will be able to see it. AHK can print to stdout, but just not to the console window.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 18th, 2008, 12:11 am 
Offline

Joined: June 26th, 2006, 6:14 pm
Posts: 1379
Location: USA
engunneer wrote:
just not to the console window.

Not true!

Run from command prompt.

Code:
ConInit()
ConW("`nThis is text from AHK Script!!! ")
Loop, 10
   ConW("`n# " . A_Index . ": This is More from AHK Script!!! ")

ConUnInit()
Return

ConInit(){
   ATTACH_PARENT_PROCESS = 0x0ffffffff ;
   DllCall("AttachConsole", "UInt", ATTACH_PARENT_PROCESS)
   }
ConUnInit(){
   DllCall("FreeConsole")
}
ConW(txt){
   FileAppend, %txt%, con
   }

_________________
Image
ʞɔпɟ əɥʇ ʇɐɥʍ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 18th, 2008, 8:44 am 
Offline

Joined: June 14th, 2005, 10:47 am
Posts: 28
@ahklerner
Great ! This works like charm, Thank you !
(Should be part of the help file ???)

@All
Thanks to everybody for your help.

edit:
now (with this keyword "AttachConsole") I found a thread that covers this problem:
http://www.autohotkey.com/forum/viewtopic.php?t=27854
Sorry, that I couldnt find it before...


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Maestr0 and 61 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group