Sign in to follow this  
Followers 0
Kyan

Get a string from command prompt

11 posts in this topic

#1 ·  Posted (edited)

Hi everyone :)

I don't know much about programming and this kind of stuff, I really started work with autoit a few days ago, so don't blame me about if it was in FAQ or elsewhere :s

How can I get the progress status from rar.exe?

in variable "$message" I'll have the ouput from rar.exe, the only code I need is xx% from prompt, how can I "convert" this to a variable and refresh every time, to set in a progress bar?

#include <Constants.au3>
$foo = Run(@ProgramFilesDir & 'winrarrar.exe', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    $message = ""
    $message = $message & $line & @LF
Wend

thanks in advance, and sorry for my bad english.

props from Portugal ;)

Edited by DiOgO

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites



Hi and welcome to AutoIt and the forum!

You have chosen an easy task to start with :)

I haven't tried it myself but maybe this can help you a bit.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

In my experience trying to grab progress output from wget... it's a royal PITA. You've got the basic framework for it. You'll need to parse the output in $line using whatever works (StringInStr or StringRegExp) on each loop, determine what info is useful, or wait to grab more output from the next loop. Once you find useful output, do something with it and clear your output buffer ($line).

Best place to start would be to capture ALL the output from an operation and print it to a file so you know the output content you're working with.

Share this post


Link to post
Share on other sites

You have chosen an easy task to start with

Hate to say I disagree. Parsing real-time progress output from command line applications, especially ones that use fancy progress output (ie wget), is NOT easy.

Share this post


Link to post
Share on other sites

Hi wraithdu,

it wasn't meant the way you understand it. See the smiley? I wanted to say that he has chosen a quite complex task to start with.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

In my experience trying to grab progress output from wget... it's a royal PITA. You've got the basic framework for it. You'll need to parse the output in $line using whatever works (StringInStr or StringRegExp) on each loop, determine what info is useful, or wait to grab more output from the next loop. Once you find useful output, do something with it and clear your output buffer ($line).

Best place to start would be to capture ALL the output from an operation and print it to a file so you know the output content you're working with.

could you give a example? (if I don't are asking to much :))

Hate to say I disagree. Parsing real-time progress output from command line applications, especially ones that use fancy progress output (ie wget), is NOT easy.

I think he's being sarcastic ;)

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites

Hi wraithdu,

it wasn't meant the way you understand it. See the smiley? I wanted to say that he has chosen a quite complex task to start with.

Apparently my internet sarcasm meter is broken today.

@DiOgO

Post some sample output that you capture from a full rar.exe run, and someone might be able to give you a pointer. It would be even more useful if you can mark in the output where each capture loop begins and ends.

For example:

#include <Constants.au3>
$foo = Run(@ProgramFilesDir & 'winrarrar.exe', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

Global $err1 = 0, $err2 = 0

While 1
    $line = StdoutRead($foo)
    If @error Then $err1 = 1
    If $line Then ConsoleWrite("|stdout|" & $line & "||" & @CRLF)
    $line = StderrRead($foo)
    If @error Then $err2 = 1
    If $line Then ConsoleWrite("|stderr|" & $line & "||" & @CRLF)
    If $err1 And $err2 Then ExitLoop
Wend

Share this post


Link to post
Share on other sites

Apparently my internet sarcasm meter is broken today.

@DiOgO

Post some sample output that you capture from a full rar.exe run, and someone might be able to give you a pointer. It would be even more useful if you can mark in the output where each capture loop begins and ends.

For example:

#include <Constants.au3>
$foo = Run(@ProgramFilesDir & 'winrarrar.exe', "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

Global $err1 = 0, $err2 = 0

While 1
    $line = StdoutRead($foo)
    If @error Then $err1 = 1
    If $line Then ConsoleWrite("|stdout|" & $line & "||" & @CRLF)
    $line = StderrRead($foo)
    If @error Then $err2 = 1
    If $line Then ConsoleWrite("|stderr|" & $line & "||" & @CRLF)
    If $err1 And $err2 Then ExitLoop
Wend

output from autoit with writefile...: http://www13.zippyshare.com/v/35557891/file.html

could you explain what is |stdout|? and what it does:

If $line Then ConsoleWrite("|stdout|" & $line & "||" & @CRLF)
  $line = StderrRead($foo)

thanks


Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Umm, it's just a string, nothing more. I was using it to mark where each line of output starts/ends. I don't see those markers in your output file. Either way, the output is pretty simple. Just use a regular expression to grab the percentages.

Edited by wraithdu

Share this post


Link to post
Share on other sites

Hi and welcome to AutoIt and the forum!

You have chosen an easy task to start with :)

I haven't tried it myself but maybe this can help you a bit.

thanks

could you explain this part: _StringStripNotNumber($ReadRarLine) ??

in this part RunRarButton displays abort, right? thats why it close rar process?

If $Msg = $RunRarButton Then
        ProcessClose($ReadRar)
        GUICtrlSetData($Progress, 0)
    EndIf

and I don't understand nothing of this line: ^ *([0-9]+.{0,1}[0-9]*|0x[0-9]+) *$ ;)


Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites

Umm, it's just a string, nothing more. I was using it to mark where each line of output starts/ends. I don't see those markers in your output file. Either way, the output is pretty simple. Just use a regular expression to grab the percentages.

regular expression? :)

in the output appears some strange characters, I think is from rar.exe upgrading the percentage value withou creating a new line...


Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0