Page 1 of 1

How to retrieve information from Bash or CMD

Posted: Feb 21st, ’17, 17:08
by joachim.weyl
How would one read in CMD and Bash output to then put through a regular expression and do some conditional testing on?

Re: How to retrieve information from Bash or CMD

Posted: Feb 22nd, ’17, 00:03
by Marko
Here is one example using AutoHotkey command syntax:

Code: Select all

RunWait %comspec% /c dir > C:\My Temp File.txt
FileRead, VarToContainContents, C:\My Temp File.txt
FileDelete, C:\My Temp File.txt
MsgBox % VarToContainContents
What exactly are trying to do?
More information: https://www.autohotkey.com/docs/FAQ.htm#output

Re: How to retrieve information from Bash or CMD

Posted: Apr 2nd, ’17, 23:32
by lehmakommionu
with the following example you can also get by without writing output to a file but the disadvantage is that the cmd.exe pops up for a second, so I personally prefer the option Marko provided earlier, where the cmd window can be hidden.

Code: Select all

FilePath=C:\test.jpg   
objShell := ComObjCreate("WScript.Shell")
objExec := objShell.Exec(ComSpec " /c C:\Users\Username\Documents\FastKeys\exiftool.exe -XPKeywords " FilePath)    ;Get the Tags/Keywords of the Image File
strStdOut := ""
while, !objExec.StdOut.AtEndOfStream
   strStdOut := objExec.StdOut.ReadAll()
MsgBox %strStdOut%
return
to hide the cmd window

Code: Select all

Runwait, %comspec% /c C:\Users\username\Documents\FastKeys\exiftool.exe -XPKeywords "%FilePath%" > C:\Users\Username\Documents\FastKeys\temp_tags.txt, , Hide   ;Write the Image Tags/Keywords Temporarily to a File