Jump to content

How to get cmd output and show in the gui


 Share

Recommended Posts

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

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 

Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

Link to comment
Share on other sites

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

EasyCodeIt - A cross-platform AutoIt implementation - Fund the development! (GitHub will double your donations for a limited time)

DcodingTheWeb Forum - Follow for updates and Join for discussion

Link to comment
Share on other sites

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

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 = Win_10   Build = 19044   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.

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

#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
Link to comment
Share on other sites

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