Jump to content

Need help processing StdOut Data


pgr
 Share

Recommended Posts

Hey guys,

I use this code snippet to read the output of the command "powercfg /L":

#include <CONSTANTS.AU3>
$PID = Run("powercfg /L", "", "", $STDOUT_CHILD)
Local $line,$timer = TimerInit()
While 1
$line = StdoutRead($PID)
If @error Then ExitLoop
if TimerDiff($timer) > 5000 Then ExitLoop ; timeout Wend
MsgBox(0, "STDOUT read:", $line)
WEnd

When I execute this script I get 2 message boxes, an empty one and one containing the output:

Existing Power Schemes (* Active)

-----------------------------------

Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced) *

Power Scheme GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c (High performance)

Power Scheme GUID: a1841308-3541-4fab-bc81-f71556f20b4a (Power saver)

What I need to do is to find all GUIDs and paste them into an array. I don´t really know where to start from here, so I would appreciate some help. The final Result should return an array containing only

381b4222-f694-41f0-9685-ff5bb260df2e

8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c

a1841308-3541-4fab-bc81-f71556f20b4a

Any Ideas?

Thanks in advance.

Link to comment
Share on other sites

ConsoleWrite(_getDOSOutput('powercfg /L') & @CRLF)
Func _getDOSOutput($command)
Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2 + 4)
While 1
  $text &= StdoutRead($Pid, False, False)
  If @error Then ExitLoop
  Sleep(10)
WEnd
Return StringStripWS($text, 7)
EndFunc   ;==>_getDOSOutput

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

For the array. (I do not have your output) Try this

#include <Array.au3>
$str = "Power Scheme GUID: 381b4222-f694-41f0-9685-ff5bb260df2e (Balanced) *" & @CRLF & _
  "Power Scheme GUID: 8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c (High performance)" & @CRLF & _
  "Power Scheme GUID: a1841308-3541-4fab-bc81-f71556f20b4a (Power saver)"
$re = StringRegExp($str, ':s*([a-z0-9-]+)s*', 3)
_ArrayDisplay($re)

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Xenobiologist, you have been a great help! ;)

The GUID vary on different PCs, thats the reason for the different output on your system. This works as expected:

#include <constants.au3>
#include <Array.au3>
$result = _getDOSOutput('powercfg /L')
$re = StringRegExp($result, ':s*([a-z0-9-]+)s*', 3)
_ArrayDisplay($re)
Func _getDOSOutput($command)
Local $text = '', $Pid = Run('"' & @ComSpec & '" /c ' & $command, '', @SW_HIDE, 2 + 4)
While 1
  $text &= StdoutRead($Pid, False, False)
  If @error Then ExitLoop
  Sleep(10)
WEnd
Return StringStripWS($text, 7)
EndFunc   ;==>_getDOSOutput

Thanks a lot for you help on this Topic. :)

PS: For future reference this is a litte more compact

$result = StringRegExp(_getDOSOutput('powercfg /L'), ':s*([a-z0-9-]+)s*', 3)
_ArrayDisplay($result)
Edited by pgr
Link to comment
Share on other sites

No problem, glad that I could help.

I know that they are different, what I meant is that my output is completely different.

Bestehende Energieschemen
-------------------------
Minimale Batteriebelastung
Minimaler Energieverbrauch
Dauerbetrieb
Pr„sentation
Tragbar/Laptop
Desktop

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

Oh. If I had to guess I´d say you use an OS < Windows 7. Maybe XP?

They changed the behavior of powercfg completely (which is driving me mad right now...). Guess its about time for an Active Directory in this company. :)

We used to set up the XP machines for our production environment with a little script that set all Power Plans to "never" so we had no blank displays or sleeping systems irritating people. ;)

;    set Power Policies 0 to 20 to "never" under all circumstances
    for $i = 0 to 20
    RunWait(@ComSpec & " /c powercfg.exe /CHANGE " & $i & " /NUMERICAL /monitor-timeout-ac 0 /monitor-timeout-dc 0 /disk-timeout-ac 0 /disk-timeout-dc 0 /standby-timeout-ac 0 /standby-timeout-dc 0 /hibernate-timeout-ac 0 /hibernate-timeout-dc 0 >NUL 2>&1", @SystemDir, @SW_HIDE)
    Next
Link to comment
Share on other sites

Yep, my business PC is still on WIN XP, because IBM tools & toys needed for development aren't fully support on WIn 7 :)

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...