Jump to content

Copy text from Console Window


Recommended Posts

Is it possible to copy text from a Console window with AutoIT? If so were would be the first place to start with the coding of that?

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

Link to comment
Share on other sites

  • Moderators

Hi, Crazyace, are you talking grabbing the output from a cmd window? If so, something like this may help:

#include <Constants.au3>

$net = Run(@ComSpec & " /c ping 192.168.1.1", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
While 1
    $line = StdoutRead($net)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Hi, Crazyace, are you talking grabbing the output from a cmd window? If so, something like this may help:

#include <Constants.au3>

$net = Run(@ComSpec & " /c ping 192.168.1.1", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
While 1
    $line = StdoutRead($net)
    If @error Then ExitLoop
    MsgBox(0, "STDOUT read:", $line)
Wend

Yes that would be correct. I'll test with the code and let you know. I'll also post back my complete code as well.

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

Link to comment
Share on other sites

Here is my complete code for my small app

#region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=..\faviconBX.ico
#AutoIt3Wrapper_Res_Comment=Beta
#AutoIt3Wrapper_Res_Fileversion=2.0.0.0
#AutoIt3Wrapper_Res_requestedExecutionLevel=asInvoker
#AutoIt3Wrapper_Run_Tidy=y
#AutoIt3Wrapper_Run_Obfuscator=n
#endregion ;**** Directives created by AutoIt3Wrapper_GUI ****
#cs ----------------------------------------------------------------------------

AutoIt Version: 3.3.9.4 (beta)
Author:      Crazyace

Script Function:
Allows you to look up your service tag, drivers, warranty and manual
Script Version:
Beta 1.0

#ce ----------------------------------------------------------------------------
; Script Start - Add your code below here
#include <GUIConstants.au3>
#include <IE.au3>
#include <Constants.au3>
GUICreate("Dell Drivers/Manuals/Warranty", 296, 110)
$Driver = GUICtrlCreateCheckbox("Drivers", 23, 10)
GUICtrlSetState(-1, $GUI_CHECKED)
$Manual = GUICtrlCreateCheckbox("Manual", 113, 10)
$Warranty = GUICtrlCreateCheckbox("Warranty", 203, 10)
GUICtrlCreateLabel("Service Tag #:", 21, 44)
$Input = GUICtrlCreateInput("", 120, 40, 155)
GUICtrlSetState(-1, $GUI_FOCUS)
$Submit = GUICtrlCreateButton("Submit", 20, 70, 70)
$Exit = GUICtrlCreateButton("Cancel", 110, 70, 70)
$FTag = GUICtrlCreateButton("Your Tag", 200, 70, 75)
Local $aAccelKeys[1][2] = [["{ENTER}", $Submit]]
GUISetAccelerators($aAccelKeys)
GUISetState(@SW_SHOW)
While 1
$msg = GUIGetMsg()
Select
  Case $msg = $GUI_EVENT_CLOSE Or $msg = $Exit
   ExitLoop
  Case $msg = $Submit
   $serv_tag = GUICtrlRead($Input)
   If Not IsChecked($Driver) And Not IsChecked($Manual) And Not IsChecked($Warranty) Then
    MsgBox(48, "Selection Error", "Pleaes make a selection first")
   ElseIf Not StringRegExp($serv_tag, "^([a-zA-Z0-9]{4}|[a-zA-Z0-9]{6})[a-zA-Z0-9]$") Then
    MsgBox(16, "Service Tag Error", "Service tag must be 5 or 7 alphanumeric characters with no spaces!")
   Else
    If IsChecked($Driver) Then _Fire($serv_tag)
    If IsChecked($Manual) Then _Fire2($serv_tag)
    If IsChecked($Warranty) Then _Fire3($serv_tag)
    ExitLoop
   EndIf
  Case $msg = $FTag
   _FindTag()
EndSelect
WEnd
Exit 0
Func _Fire($sServiceTag)
$oIE = _IECreate("http://www.dell.com/support/drivers/us/en/04/DriversHome/NeedProductSelection", 0, 1, 0)
EndFunc   ;==>_Fire
Func _Fire2($sServiceTag)
$oIE = _IECreate("http://support.dell.com/support/topics/global.aspx/support/my_systems_info/manuals?c=us&l=en&s=biz&~ck=ln&lnki=0&ServiceTag=" & $sServiceTag, 0, 1, 0)
EndFunc   ;==>_Fire2
Func _Fire3($sServiceTag)
$oIE = _IECreate("http://support.dell.com/support/topics/global.aspx/support/my_systems_info/details?c=us&cs=555&l=en&s=biz&~ck=anavml&ServiceTag=" & $sServiceTag, 0, 1, 0)
EndFunc   ;==>_Fire3
Func _FindTag()
Opt("WinTitleMatchMode", 2)
$CMD = Run(@ComSpec & " /c wmic csproduct list brief", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
While 1
  $line = StdoutRead($CMD)
  If @error Then ExitLoop
  MsgBox(0, "STDOUT read:", $line)
WEnd
EndFunc   ;==>_FindTag
Func IsChecked($control)
Return BitAND(GUICtrlRead($control), $GUI_CHECKED) = $GUI_CHECKED
EndFunc   ;==>IsChecked

Here is the code part for the Console Window

Func _FindTag()
Opt("WinTitleMatchMode", 2)
$CMD = Run(@ComSpec & " /c wmic csproduct list brief", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
While 1
  $line = StdoutRead($CMD)
  If @error Then ExitLoop
  MsgBox(0, "STDOUT read:", $line)
WEnd
EndFunc   ;==>_FindTag

When running it will pop up a blank box and then pop up a 2nd box after clicking ok that has the info from the command. Why does it do that?

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

Link to comment
Share on other sites

  • Moderators

It's just the way StdoutRead grabs the console window. If you want to remove it, just use an IF statement:

#include <Constants.au3>

$net = Run(@ComSpec & " /c ping 10.213.16.91", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD)
While 1
    $line = StdoutRead($net)
    If @error Then ExitLoop
If $line <> "" Then
  MsgBox(0, "STDOUT read:", $line)
EndIf
Wend

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

It's just the way StdoutRead grabs the console window. If you want to remove it, just use an IF statement:

#include  $net = Run(@ComSpec & " /c ping 10.213.16.91", @SystemDir, @SW_HIDE, $STDERR_CHILD + $STDOUT_CHILD) While 1 $line = StdoutRead($net) If @error Then ExitLoop If $line <> "" Then MsgBox(0, "STDOUT read:", $line) EndIf Wend
Thanks for the follow up. So what I would like to do next is use
StringRegExp($line, "^([a-zA-Z0-9]{4}|[a-zA-Z0-9]{6})[a-zA-Z0-9]$")
and then have that set the input box. I tried a few different things but it wasn't happy lol Edited by Crazyace

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

Link to comment
Share on other sites

  • Moderators

Unfortunately you'll have to wait for someone much more intelligent than I to wander by. StringRegExp make my eyes bleed ;)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Unfortunately you'll have to wait for someone much more intelligent than I to wander by. StringRegExp make my eyes bleed ;)

No problem, but thank you ever so much for the help!

"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.""Never, ever, argue with an idiot. They'll drag you down to their level and beat you with experience"

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

×
×
  • Create New...