SeharH

How to get cmd output and show in the gui

45 posts in this topic

#1 ·  Posted (edited)

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



#2 ·  Posted

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 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

#3 ·  Posted

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

#4 ·  Posted (edited)

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

#5 ·  Posted

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 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

#6 ·  Posted

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

#7 ·  Posted (edited)

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 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

#8 ·  Posted

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

#9 ·  Posted

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


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

#10 ·  Posted

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

#11 ·  Posted

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 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

#12 ·  Posted

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

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

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

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

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

#14 ·  Posted

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

Some messages & Apologizes:

If I hurt you, Please accept my apologies, I never (regardless of the situation) mean to hurt anybody!!!

Also, I am very busy with my project so I will appear in the last row of the online list, if you want to contact me: Email@TheDcoder.xyz

Or you can have a nice chat with me in freenode, I use the same nick on freenode too!

3fHNZJ.gif

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

Share this post


Link to post
Share on other sites

#15 ·  Posted

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

#16 ·  Posted

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

#17 ·  Posted

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


SciTE = 3.6.2.0/full   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

#18 ·  Posted

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

#19 ·  Posted (edited)

#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

#20 ·  Posted (edited)

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