Sign in to follow this  
Followers 0
mcsdex2

Capture Commandline output only first line

3 posts in this topic

Local $answer = InputBox("Question", "Uptime for what Computer?", "", "", _

- 1, -1, Default, Default)

$boottime = '"Boot Time"'

Local $foo = Run (@ComSpec & " /k" & "systeminfo.exe /s" & " " & $answer & " | Find " & $boottime, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD )

Local $line

SplashTextOn ("Retrieving Information", "Please wait ...", 200, 100, -1, -1, 32, "Georgia", 10)

ProcessWaitClose ($foo)

SplashOff ()

While 1

$line = StdoutRead($foo)

If @error Then ExitLoop

MsgBox(0, "Success Return UpTime:", $answer & " Last " & $line )

Wend

While 1

$line = StderrRead($foo)

If @error Then ExitLoop

MsgBox(0, "Failure Return Uptime:", $answer & " " & "Computer cannot be found!")

Wend

I am wondering if someone could point me in the right direction as I cannot seem to just capture the first line of the run command output to a msgbox. There is the script and if you have questions please ask as I think I may need to re-write it to a text file first then append it from there.

Share this post


Link to post
Share on other sites



This & " /k" & "systeminfo.exe /s" is missing a space after the K and should be & " /k systeminfo.exe /s".


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

mcsdex2,

I would create a variable of all output instead of piping the output through the find command. This will let you interrogate additional values more easily.

Like this...

#include <constants.au3>
#include <array.au3>

Local $answer = InputBox("Question", "Uptime for what Computer?", "", ""), $cmd_output, $line

Local $foo = Run(@ComSpec & " /k " & "systeminfo.exe /s " & $answer, @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)

SplashTextOn ("Retrieving Information", "Please wait ...", 200, 100, -1, -1, 32, "Georgia", 10)
ProcessWaitClose ($foo)
SplashOff ()

While 1
    $line = StdoutRead($foo)
    If @error Then ExitLoop
    if stringlen($line) > 0 then $cmd_output &= $line
WEnd

While 1
    $line = StderrRead($foo)
    If @error Then ExitLoop
    if stringlen($line) > 0 then $cmd_output &= $line
WEnd

local $boottime = stringregexp($cmd_output,'Boot Time.*',3)

if @error = 0 then
    ConsoleWrite($boottime[0] & @LF)
Else
    ConsoleWrite('Not Found' & @LF & $cmd_output & @lf)
endif

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

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