Jump to content
SeharH

How to get cmd output and show in the gui

Recommended Posts

SeharH

Hello every one

Iam really new'be to autoit and to any script writing so advanclly sorry if iam not following the right way to ask the things.

 

Come to the point.---

 

Currently i do write a script in autoit for android devicesGbiyQFf.png

i do run commands from adb shell cmd.now my question is how to show the out put result into my gui.like below i run a command and i want to show its out put into my gui.

 

bmF3myQ.png

 

 

I do really respect of my all of seniors  kindly help me out Thanks

Edited by SeharH

Share this post


Link to post
Share on other sites
water

Welcome to AutoIt and the forum!

If you use Run in your AutoIt script to execute the command you could set parameter opt_flag to $STDOUT_CHILD to grab the output of your command.
Function SdtoutRead then allows to read this output and process in your script.
Please check the help file for functions Run and StdoutRead for further details and examples.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
SeharH

Well Very much thanks you 

Iam totally new here so let me make a demo fram so you can please guide me for what to do and where to do Thanks

Share this post


Link to post
Share on other sites
SeharH

here is simple frame with single button and edit box where i want to show the out put

 

yTGZHtq.png

 

f3qdn0r.png

 

Code

 

Quote

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 577, 329, 330, 318)
$Buildprop = GUICtrlCreateButton("Build.prop Info", 24, 56, 113, 185)
$Logs = GUICtrlCreateEdit("", 216, 56, 297, 193, BitOR($GUI_SS_DEFAULT_EDIT,$ES_READONLY))
GUICtrlSetData(-1, "Logs")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


If Not FileExists(@TempDir & "\adb.exe") Then
    FileInstall("adb.exe", @TempDir & "\adb.exe", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinApi.dll") Then
    FileInstall("AdbWinApi.dll", @TempDir & "\AdbWinApi.dll", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinUsbApi.dll") Then
    FileInstall("AdbWinUsbApi.dll", @TempDir & "\AdbWinUsbApi.dll", 1)
EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case @Buildprop
             Buildprop()
    EndSwitch
 WEnd

Func Buildprop()
    Run("adb shell getprop ro.build.id","".@SW_HIDE)

 

Edited by SeharH

Share this post


Link to post
Share on other sites
water

Use this (or something similar) to grab all output of your command:

Global $iPID = Run("adb shell getprop ro.build.id","".@SW_HIDE), $STDOUT_CHILD)
Global $sOutput = ""
While 1
    $sOutput = StdoutRead($iPID)
    If @error Then ExitLoop ; Exit the loop if the process closes or StdoutRead returns an error.
    MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)
WEnd

 


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
SeharH
4 minutes ago, water said:

Global $iPID = Run("adb shell getprop ro.build.id","".@SW_HIDE), $STDOUT_CHILD) Global $sOutput = "" While 1 $sOutput = StdoutRead($iPID) If @error Then ExitLoop ; Exit the loop if the process closes or StdoutRead returns an error. MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)

Over my head

 

Sorry but really i have no idea where to add these codes and how to alighn them.Iam highly apriciated if you can edit for me simple frame 

Share this post


Link to post
Share on other sites
water

Imbed this lines in your script as function Buildprop:

Local $iPID = Run("adb shell getprop ro.build.id","".@SW_HIDE), $STDOUT_CHILD)
Local $sLogs = ""
While 1
    $sLogs = $sLogs & @CRLF & StdoutRead($iPID)
    If @error Then ExitLoop ; Exit the loop if the process closes or StdoutRead returns an error.
WEnd

 

Edited by water

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
SeharH

Sorry but can you please embed for me in my code so i can understand where to set these line

My code

 

Quote

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 577, 329, 330, 318)
$Buildprop = GUICtrlCreateButton("Build.prop Info", 24, 56, 113, 185)
$Logs = GUICtrlCreateEdit("", 216, 56, 297, 193, BitOR($GUI_SS_DEFAULT_EDIT,$ES_READONLY))
GUICtrlSetData(-1, "Logs")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


If Not FileExists(@TempDir & "\adb.exe") Then
    FileInstall("adb.exe", @TempDir & "\adb.exe", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinApi.dll") Then
    FileInstall("AdbWinApi.dll", @TempDir & "\AdbWinApi.dll", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinUsbApi.dll") Then
    FileInstall("AdbWinUsbApi.dll", @TempDir & "\AdbWinUsbApi.dll", 1)
EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
         Case @Buildprop
             Buildprop()
    EndSwitch
 WEnd

Func Buildprop()
    Run("adb shell getprop ro.build.id","".@SW_HIDE)

 

Share this post


Link to post
Share on other sites
water

As I stated above: Insert my code in your function Buildprop.


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
SeharH

Where iam making mistake :sweating:

 

eiBSllU.png

 

 

accept my appoligize sir for being not understand anything yet 

Share this post


Link to post
Share on other sites
water

Line 11: Remove the bracket after @SW_Hide.
Line 33: Replace @ with $
Line 39: The dot before @SW_Hide, should be a comma


My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2018-10-19 - Version 1.4.10.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (2018-10-31 - Version 1.3.4.1) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
PowerPoint (2017-06-06 - Version 0.0.5.0) - Download - General Help & Support
Excel - Example Scripts - Wiki
Word - Wiki
 
Tutorials:

ADO - Wiki

 

Share this post


Link to post
Share on other sites
TheDcoder

Hello, you can find a good example of capturing the output of a commandline program in my Process UDF, Just download the repository and play with Example.au3 :D


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
SeharH
10 minutes ago, water said:

Line 11: Remove the bracket after @SW_Hide.
Line 33: Replace @ with $
Line 39: The dot before @SW_Hide, should be a comma

Followed and left it now with this one on below

 

 

JvoLr5L.png

 

Thanks sir very much for bieng help me allot

Edited by SeharH

Share this post


Link to post
Share on other sites
TheDcoder

Replace the dot/fullstop with a comma on line 11


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Spoiler

My contributions to the AutoIt Community

If I have hurt or offended you in anyway, Please accept my apologies, I never (regardless of the situation) mean to do that to anybody!!!

3fHNZJ.gif

PLEASE JOIN ##AutoIt AND HELP THE IRC AUTOIT COMMUNITY!

Share this post


Link to post
Share on other sites
SeharH

well much improved but while i press Build prop info button than there is no out put show in the gui

 

sJuJetG.png

 

i have removed the line because the gui has been dissappear

Quote
If @error Then ExitLoop ; Exit the loop if the process closes or StdoutRead returns an error.

 

Share this post


Link to post
Share on other sites
SeharH

so i want to show the out put on pointed area any where

 

ytNl8KX.png

Share this post


Link to post
Share on other sites
Simpel

Put the scripted part by @water into your function Buildprop instead of inserting some of the lines everywhere inside your script:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3> ; add because of declaration $STDOUT_CHILD
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 577, 329, 330, 318)
$Buildprop = GUICtrlCreateButton("Build.prop Info", 24, 56, 113, 185)
Global $Logs = GUICtrlCreateEdit("", 216, 56, 297, 193, BitOR($GUI_SS_DEFAULT_EDIT,$ES_READONLY)) ; make it Global, so that Func Buildprop() can use it
GUICtrlSetData(-1, "Logs")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


If Not FileExists(@TempDir & "\adb.exe") Then
    FileInstall("adb.exe", @TempDir & "\adb.exe", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinApi.dll") Then
    FileInstall("AdbWinApi.dll", @TempDir & "\AdbWinApi.dll", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinUsbApi.dll") Then
    FileInstall("AdbWinUsbApi.dll", @TempDir & "\AdbWinUsbApi.dll", 1)
EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Buildprop
            Buildprop()
    EndSwitch
WEnd

Func Buildprop()
    Local $iPID = Run("adb shell getprop ro.build.id","",@SW_HIDE, $STDOUT_CHILD)
    Local $sLogs = ""
    While 1
        $sLogs = $sLogs & @CRLF & StdoutRead($iPID)
        If @error Then ExitLoop ; Exit the loop if the process closes or StdoutRead returns an error.
    WEnd
    GUICtrlSetData($Logs, $sLogs) ; Set the $sLog into your Edit
EndFunc

Regards, Conrad


SciTE4AutoIt = 3.7.3.0   AutoIt = 3.3.14.2   AutoItX64 = 0   OS = Win7Pro SP1   OSArch = X64   Language = 0407/german
H:\...\AutoIt3\SciTE     H:\...\AutoIt3      H:\...\AutoIt3\Include     (H:\ = Network Drive)

   88x31.png  Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind.

Share this post


Link to post
Share on other sites
SeharH
3 minutes ago, Simpel said:

Put the scripted part by @water into your function Buildprop instead of inserting some of the lines everywhere inside your script:

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <AutoItConstants.au3> ; add because of declaration $STDOUT_CHILD
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 577, 329, 330, 318)
$Buildprop = GUICtrlCreateButton("Build.prop Info", 24, 56, 113, 185)
Global $Logs = GUICtrlCreateEdit("", 216, 56, 297, 193, BitOR($GUI_SS_DEFAULT_EDIT,$ES_READONLY)) ; make it Global, so that Func Buildprop() can use it
GUICtrlSetData(-1, "Logs")
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


If Not FileExists(@TempDir & "\adb.exe") Then
    FileInstall("adb.exe", @TempDir & "\adb.exe", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinApi.dll") Then
    FileInstall("AdbWinApi.dll", @TempDir & "\AdbWinApi.dll", 1)
EndIf
If Not FileExists(@TempDir & "\AdbWinUsbApi.dll") Then
    FileInstall("AdbWinUsbApi.dll", @TempDir & "\AdbWinUsbApi.dll", 1)
EndIf

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Buildprop
            Buildprop()
    EndSwitch
WEnd

Func Buildprop()
    Local $iPID = Run("adb shell getprop ro.build.id","",@SW_HIDE, $STDOUT_CHILD)
    Local $sLogs = ""
    While 1
        $sLogs = $sLogs & @CRLF & StdoutRead($iPID)
        If @error Then ExitLoop ; Exit the loop if the process closes or StdoutRead returns an error.
    WEnd
    GUICtrlSetData($Logs, $sLogs) ; Set the $sLog into your Edit
EndFunc

Regards, Conrad

Finally.Thanks you all my seniors so much Soon i will share my script

4SxLb8T.png

 

Share this post


Link to post
Share on other sites
kosamja
#NoTrayIcon
#RequireAdmin
#include <Constants.au3>
#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

Global $Form1 = GUICreate("Form1", 577, 329, 330, 318)
Global $Buildprop = GUICtrlCreateButton("Build.prop Info", 24, 56, 113, 185)
Global $Logs = GUICtrlCreateEdit("", 216, 56, 297, 193, BitOR($GUI_SS_DEFAULT_EDIT,$ES_READONLY))
GUICtrlSetOnEvent($Buildprop, '_Buildprop')
GUISetOnEvent($GUI_EVENT_CLOSE, '_AllExit', $Form1)
GUICtrlSetData($Logs, "Logs" & @CRLF)
GUISetState(@SW_SHOW, $Form1)

If not FileExists(@TempDir & "\adb.exe") Then FileInstall("adb.exe", @TempDir & "\adb.exe", $FC_OVERWRITE)
If not FileExists(@TempDir & "\AdbWinApi.dll") Then FileInstall("AdbWinApi.dll", @TempDir & "\AdbWinApi.dll", $FC_OVERWRITE)
If not FileExists(@TempDir & "\AdbWinUsbApi.dll") Then FileInstall("AdbWinUsbApi.dll", @TempDir & "\AdbWinUsbApi.dll", $FC_OVERWRITE)

While 1
   Sleep(1000)
WEnd

Func _AllExit()
   GUIDelete(@GUI_WinHandle)
   Exit
EndFunc

Func _Buildprop()
   $iPID = Run("adb shell getprop ro.build.id", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
   ProcessWaitClose($iPID)
   $sOutput = StringStripWS(StdoutRead($iPID), $STR_STRIPLEADING + $STR_STRIPTRAILING)
   GUICtrlSetData($Logs, GUICtrlRead($Logs) & 'Display id | ' & $sOutput & @CRLF)
EndFunc

 

Edited by kosamja

Share this post


Link to post
Share on other sites
SeharH
10 minutes ago, kosamja said:
#NoTrayIcon
#RequireAdmin
#include <Constants.au3>
#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

Global $Form1 = GUICreate("Form1", 577, 329, 330, 318)
Global $Buildprop = GUICtrlCreateButton("Build.prop Info", 24, 56, 113, 185)
Global $Logs = GUICtrlCreateEdit("", 216, 56, 297, 193, BitOR($GUI_SS_DEFAULT_EDIT,$ES_READONLY))
GUICtrlSetOnEvent($Buildprop, '_Buildprop')
GUISetOnEvent($GUI_EVENT_CLOSE, '_AllExit')
GUICtrlSetData($Logs, "Logs")
GUISetState(@SW_SHOW, $Form1)

Select
Case not FileExists(@TempDir & "\adb.exe")
    FileInstall("adb.exe", @TempDir & "\adb.exe", $FC_OVERWRITE)
Case not FileExists(@TempDir & "\AdbWinApi.dll")
    FileInstall("AdbWinApi.dll", @TempDir & "\AdbWinApi.dll", $FC_OVERWRITE)
Case not FileExists(@TempDir & "\AdbWinUsbApi.dll")
    FileInstall("AdbWinUsbApi.dll", @TempDir & "\AdbWinUsbApi.dll", $FC_OVERWRITE)
EndSelect

While 1
   Sleep(1000)
WEnd

Func _AllExit()
   GUIDelete(@GUI_WinHandle)
   Exit
EndFunc

Func _Buildprop()
   $iPID = Run("adb shell getprop ro.build.id", "", @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
   ProcessWaitClose($iPID)
   $sOutput = StdoutRead($iPID)
   MsgBox($MB_SYSTEMMODAL, "Stdout Read:", $sOutput)
EndFunc

 

Also good idea but i dont want to open out put in dialogbox i want to show the out put in bellow area

also now my question is how to set the output value name so when i ever i get result of "adb shell getprop ro.build.id" than i get out put as below

Display id | LMY47V 

 

Also output txt has been copied into logs box very down whats that issue?

Example  

WUyEHFz.png

 

Edited by SeharH

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

×