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 

Filtering Stdout

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





PostPosted: Thu Mar 25, 2004 9:04 am    Post subject: Filtering Stdout Reply with quote

My all time favourite:
to be able to pipe a DOS command output (as a single var) from the commandline to the memory/clipboard to filter it with IfInString.

Sample:

Quote:
Run, %COMSPEC% /C DIR C:\*.* /B /O:N /L > %MyVar%
IfInString, MyVar, MyFileName, Exit


It wouldn't be necessary to dump the stdout(put) to a file for filtering. As I've never seen it (except with VBS/WSH under W2K&XP) it seems to be a problem to accomplish that Sad Currently you're forced to open a document to grep its "visible" content:

Quote:
Run, %COMSPEC% /C DIR C:\*.* /B /O:N /L > C:\Dir.txt
Run, Notepad C:\Dir.txt
WinWait, Dir.txt - Notepad
Send, ^a
Send, ^c
IfInString, CLIPBOARD, MyFileName, MsgBox, 0, DirResult, Yep - it's there !
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Thu Mar 25, 2004 1:26 pm    Post subject: Reply with quote

Good idea, I'll look into it. In the meantime, this might interest you:

Run, %COMSPEC% /C DIR C:\*.* /B /O:N /L | find "search word" >dir.txt

The above will use the FIND command to filter in the command interpreter for you. Then the file will contain only the desired filename.

Another way that doesn't need notepad:
Code:
RunWait, %COMSPEC% /C DIR C:\*.* /B /O:N /L >c:\dir.txt
Loop, read, c:\dir.txt
     IfInString, A_LoopReadLine, autoexec, MsgBox, Found it.


And finally, an even easier way, but that only applies to your one example (you probably wanted it to work with other comspec commands also):

IfExist, C:\MyFile.txt, MsgBox, Yes it exists.

Or if you need something more flexible:
Code:
Loop, C:\*.*
     IfInString, A_LoopFileName, autoexec, MsgBox, Found it.



Finally, I think there are free file2clip type programs (I think there's one in the AutoIt mailing list archives) you can get to redirect output to the clipboard like this:

Run, %COMSPEC% /C DIR C:\*.* /B /O:N /L | file2clip.exe

The above would put the results onto the clipboard, which can be used like a variable by AHK. You could save and restore the clipboard's former contents if needed.

I'm going to keep your suggestion in mind and see if there is some way to achieve it, though I can't think of any way to directly program it. In the meantime, hopefully one of the above will be of interest.
Back to top
View user's profile Send private message Send e-mail
Beastmaster
Guest





PostPosted: Thu Mar 25, 2004 5:54 pm    Post subject: Reply with quote

Thx for your response.

To search for a filename isn't really what I want to accomplish (I used it only cause its a commonly known standard doing a search).

I would be interested in parsing files for patterns (and that without creating a file in advance !), otherwise a grep/egrep would have solved such an issue as well Wink

BTW&FYI.
The file2clip.exe which I've googled will cut a file's path which has been previously drag&dropped to its GUI and pipes the ouput into the clipboard.
Crying or Very sad
Back to top
Chris
Site Admin


Joined: 02 Mar 2004
Posts: 10467

PostPosted: Thu Mar 25, 2004 8:22 pm    Post subject: Reply with quote

I found this tool lying around in my collection. It was written by Dave Navarro.

Quote:
CLIP also supports redirection and pipes. You can copy the output of any applications that writes to STDOUT into the clipboard:

DIR | CLIP.EXE

Or simply redirect text:

CLIP < filename.txt


I've put a copy of it below. Hopefully it will be of some use to you (I might use it more often myself):

http://www.autohotkey.com/misc/clip.zip

Edit: I think the above might have some reliability problems. I re-compiled a different utility that seems to work, though it only supports a maximum of 512 KB of text:
http://www.autohotkey.com/misc/cb.zip


Last edited by Chris on Fri Jul 02, 2004 12:21 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
Beastmaster
Guest





PostPosted: Thu Mar 25, 2004 9:34 pm    Post subject: Reply with quote

Thx, Chris.
Clip, that's it ! Very Happy
Back to top
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