GZM Posted February 2, 2016 Share Posted February 2, 2016 Hi everybody! Very happy to finally join you all. I´m starting to work in a project as a hobbie. Well, I've made some scripts a while ago, but let´s say I'm a complete newbie, both to AutoIt and programming itself, so please don't be that hard on me. Just feel free to correct me if I make any mistake. I want to translate a program's verbose output (console) into meaningful information on a GUI (Progress bar, ratio, estimated time to finish, etc). Eventually, I would want my prog to become a somewhat universal parser for other command-line tools. The program is precomp. It´s output is pretty simple (but in verbose mode is a nightmare). Should I start reading the simple output or must consider the worst case to begin with? Sadly, I have basically no clue about where to start... Could you please give some ideas on the script structure? Thanks in advance! Link to comment Share on other sites More sharing options...
TheDcoder Posted February 2, 2016 Share Posted February 2, 2016 @GZM You can follow Best Coding Practices to start with... Use #Regions to fold code... Avoid using Magic Numbers etc etc... I also made a UDF called "Process UDF" (Link in my signature) which contains functions to get the command line output from a program (Though, its a bit outdated ) Good luck EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time) DcodingTheWeb Forum - Follow for updates and Join for discussion Link to comment Share on other sites More sharing options...
GZM Posted February 2, 2016 Author Share Posted February 2, 2016 1 minute ago, TheDcoder said: @GZM You can follow Best Coding Practices to start with... Use #Regions to fold code... Avoid using Magic Numbers etc etc... I also made a UDF called "Process UDF" (Link in my signature) which contains functions to get the command line output from a program (Though, its a bit outdated ) Good luck Yeah, this is useful, indeed. Thank you for the quick answer! Link to comment Share on other sites More sharing options...
JohnOne Posted February 2, 2016 Share Posted February 2, 2016 (edited) Start by looking at the following functions in the help file and trying the examples. Run() STDOutRead() You can click them to go to online help, but better to use help file locally, so you can directly open the example scripts. Edited February 2, 2016 by JohnOne AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
orbs Posted February 2, 2016 Share Posted February 2, 2016 @GZM, sorry to be a party crusher, but would you mind ease our concern about that console program of yours, "precomp". it seems to be game-related, and this is handled according to these directives. if it is not the "precomp.exe" as described here, you can get a better assistance if you post an example of the output. Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Link to comment Share on other sites More sharing options...
GZM Posted February 2, 2016 Author Share Posted February 2, 2016 @JohnOne:Thank you. Seems like what I need. @orbs: Yes, I understand your concern. Precomp is a tool for 'un-doing' some weak compression techniques, (like zlib's deflate, or GIG's LZW) to finally improve the overall ratio. It is a serious tool looking for state-of-the-art results on data compression. But, given its functionality, it has been widely used on the game "repacking" scene (aka Warez). Annoying, I know. Well, I assure you, this is not what I´m doing. Actually, I dont even like games. It's just I really like this little piece of software. Official GitHub repo Threads on encode.ru Normal output: Precomp v0.4.5 - DEVELOPMENT version - USE AT YOUR OWN RISK! Free for non-commercial use - Copyright 2006-2016 by Christian Schneider Input file: 01 - Elemental electr¾nica.pdf Output file: 01 - Elemental electr¾nica.pcf Using PackJPG for JPG recompression, PackMP3 for MP3 recompression. --> packJPG library v2.5j (01/15/2014) by Matthias Stirner / Se <-- --> packMP3 library v1.0f (11/21/2014) by Matthias Stirner <-- More about PackJPG and PackMP3 here: http://www.matthiasstirner.com 100.00% - New size: 26157203 instead of 31064028 Done. Time: 3 minute(s), 33 second(s) Recompressed streams: 144/244 PDF streams: 98/149 JPG streams: 46/46 zLib streams (intense mode): 0/49 You can speed up Precomp for THIS FILE with these parameters: -zl11,67,85,97,98,99 Verbose output: LOG.txt Link to comment Share on other sites More sharing options...
GZM Posted February 2, 2016 Author Share Posted February 2, 2016 @orbs: BTW, I'm just as pissed of as anybody else looking at how science is turned into toys used by irresponsible grown-ups children... Another great tool went into Warez scene is srep. The same apply to Freearc, both by Bulat Ziganshin. Or Zpaq, the very strongest compressor known by this time. czardas 1 Link to comment Share on other sites More sharing options...
GZM Posted February 2, 2016 Author Share Posted February 2, 2016 Ok... Tried "Process UDF", but it only reads the output once the command is done. I need realtime feedback. Is there any way to include a GUI artifact inside the "ConsoleRead()" loop? I made a minor modification on the example and partially worked. At least ran an MsgBox each time the last is closed. Is it possible to have a single GUI updating itself? I also tried Run() with option $STDOUT_CHILD and STDOutRead() but this also reads everything at the end. Link to comment Share on other sites More sharing options...
JohnOne Posted February 2, 2016 Share Posted February 2, 2016 Then you probably done it wrong. Show code. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
GZM Posted February 2, 2016 Author Share Posted February 2, 2016 33 minutes ago, JohnOne said: Show code. This is a copy-paste from StdoutRead.au3 (offline help): ; Wait until the process has closed using the PID returned by Run. ProcessWaitClose($iPID) ; Read the Stdout stream of the PID returned by Run. This can also be done in a while loop. Look at the example for StderrRead. Local $sOutput = StdoutRead($iPID) This is from example.au3 (TheDcoder's Process UDF): MsgBox($MB_ICONINFORMATION, "Demo", 'Demo for _Process_RunCommand in RUNWAIT mode, This is the function line: _Process_RunCommand($PROCESS_RUNWAIT, $PROCESS_COMMAND & "ping 127.0.0.1")' & @CRLF & @CRLF & "(This will take some time)") $sOutput = _Process_RunCommand($PROCESS_RUNWAIT, $PROCESS_COMMAND & "ping 127.0.0.1") ; Record the output $iExitCode = @extended ; Note the exit code MsgBox($MB_ICONINFORMATION, "Demo", "This is the result: " & @CRLF & @CRLF & $sOutput & @CRLF & @CRLF & "The exit code was: " & $iExitCode) The only case in which the output is shown real-time is using _Process_DebugRunCommand () as below: MsgBox($MB_ICONINFORMATION, "Demo", 'Demo for _Process_RunCommand in RUN mode and Demo for _Process_DebugRunCommand, This is the function line: _Process_RunCommand($PROCESS_RUN, $PROCESS_COMMAND & "tracert google.com")' & @CRLF & @CRLF & "This will be a fun ride :D") $hProcessHandle = _Process_RunCommand($PROCESS_RUN, $PROCESS_COMMAND & "tracert google.com") ; Capture the Process Handle $iPID = @extended ; Note the PID _Process_DebugRunCommand($hProcessHandle, $iPID) ; Display the results in real-time The first two scripts waits until the program is done to show the output. The last one open up a pseudo-cmd window, just like if I wite "cmd /k my_program"... Link to comment Share on other sites More sharing options...
JohnOne Posted February 2, 2016 Share Posted February 2, 2016 Looks like someone removed an important example from the help file. pseudo $pid = Run() While ProcessExists($pid) StdOutRead($pid) ; each line here WEnd AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
GZM Posted February 2, 2016 Author Share Posted February 2, 2016 28 minutes ago, JohnOne said: Looks like someone removed an important example from the help file. pseudo $pid = Run() While ProcessExists($pid) StdOutRead($pid) ; each line here WEnd Well, I try to keep up... Not easy yet. So thank you for being patient. Could you post a more specific example? Thanks in advance! Link to comment Share on other sites More sharing options...
kylomas Posted February 2, 2016 Share Posted February 2, 2016 Gzm, Post your code so we can correct/build on it. Kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
GZM Posted February 2, 2016 Author Share Posted February 2, 2016 1 minute ago, kylomas said: Gzm, Post your code so we can correct/build on it. Kylomas Let's see another example of what I'm trying to do. This is from StderrRead.au3, just slightly modified to run a custom command instead of the original: #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Example() Func Example() Local $iPID = Run(@ComSpec & " /k Bat.bat", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $sOutput = "" While 1 $sOutput = StdoutRead($iPID) If @error Then ; Exit the loop if the process closes or StdoutRead returns an error. ExitLoop EndIf MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput) WEnd While 1 $sOutput = StderrRead($iPID) If @error Then ; Exit the loop if the process closes or StderrRead returns an error. ExitLoop EndIf MsgBox($MB_SYSTEMMODAL, "Stderr Read:", $sOutput) WEnd EndFunc ;==>Example What I get from this is an empty MsgBox, another one with the first line on the batch and then an infinite loop of empty MsgBoxes... Link to comment Share on other sites More sharing options...
GZM Posted February 2, 2016 Author Share Posted February 2, 2016 Now I replaced @ComSpec & " /k Bat.bat" with fazip lz4:hc TEST TEST.lz4 Again empty msgboxes with no text Link to comment Share on other sites More sharing options...
kylomas Posted February 2, 2016 Share Posted February 2, 2016 Gmz, You are completely missing the point. Unfortunately i am not at a pc and dont have time right now to get into it. However, if you want to process the outout stream as it is written then put you code within the loop that gets it. Note, some things do not produce console output. Kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
JohnOne Posted February 2, 2016 Share Posted February 2, 2016 (edited) #include <AutoItConstants.au3> #include <MsgBoxConstants.au3> Example() Func Example() Local $iPID = Run(@ComSpec & ' /C DIR ', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) Local $sOutput = "" While 1 $sOutput = StdoutRead($iPID) If @error Then ; Exit the loop if the process closes or StdoutRead returns an error. ExitLoop EndIf ConsoleWriteLine($sOutput) WEnd EndFunc ;==>Example Func ConsoleWriteLine($str) If $str <> "" Then ConsoleWrite($str & @LF) EndIf EndFunc ;==>ConsoleWriteLine Edited February 2, 2016 by JohnOne GZM 1 AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
GZM Posted February 3, 2016 Author Share Posted February 3, 2016 @all: Thank you for the feedback. Well, this is a starting. By changing StdoutRead to StderrRead in @JohnOne script, I've managed to read the console output... The only drawback, it appears every ~16 seconds. Let´s see if it can be tuned. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now