Jump to content

Reading Data Returned from @ComSpec


Nunos
 Share

Recommended Posts

36 minutes ago, jdelaney said:

This might be easier:

run(@ComSpec & ' /c sqlcmd -Lc  > output.txt')

Then just _filereadtoarray the output.txt.

I don't recall if sqlcmd eats the pipe, but if it does, there is another parameter you can add to output to a file.

I think the array is being created just not doing the pattern match properly for some reason. I can try to get it into a txt file then an array but I still need to search it for each Server Instance and Database Instance to get it into a gui so the end user can choose which matched pair is associated with their system. I think my problem lies in the $spattern = "\h+([\w\\-]+)"
Local $aArray = StringRegExp($sOutput, $spattern,3)

portion of the script but I am struggling to understand what I need to change to get a match on the $spattern I have tried several variations but I don't seem to be landing on what I need. I think the "-" in the naming convention for the server instances might be causing part of the problem but I am unsure.

Edited by Nunos
Link to comment
Share on other sites

The last line DW-MWS\Dinerware

 

 

However on some locations that list might have 5 comboniations like below so I just need to make sure that they are matched up properly.

 

DW-MWS

DW-MWS\Dinerware

MD-MWS\Dinerware001

WS01\Dinerware

MDSRV\DINERWARE01

 

So I was thinking that the only thing that should always appear is the backslash between the ServerInstance and the actual Database Name. At one point I had it getting them but on ones that have a hyphen in the name it was not gathering the hyphen and characters left of it.

Link to comment
Share on other sites

Nunos,

Try this, not sure if it is where you are going...

#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <GuiComboBox.au3>

Local $str = FileRead(@ScriptDir & '\output.txt')

ConsoleWrite($str & @CRLF)

;$spattern = '\h+([\w\\-]+)'
$spattern = '(?m)^.*\\.*$'

Local $array = StringRegExp($str, $spattern, 3)

;_arraydisplay($array)

; to populate a combo box from the array do...

Local $gui010 = GUICreate('CB Example')
GUICtrlCreateLabel('Node', 20, 20, 100, 20)
Local $cmb010 = GUICtrlCreateCombo('', 20, 40, 150, 300)
GUICtrlCreateLabel('DB', 220, 20, 100, 20)
Local $cmb020 = GUICtrlCreateCombo('', 220, 40, 150, 300)

; populate combo boxes

For $1 = 0 To UBound($array) - 1
    GUICtrlSetData($cmb010, StringRegExpReplace($array[$1], '([^\\]+).*', '$1'))
    GUICtrlSetData($cmb020, StringRegExpReplace($array[$1], '[^\\]+\\(.*)', '$1'))
Next

; set entry 0 as current (default) selection

_GUICtrlComboBox_SetCurSel($cmb010, 0)
_GUICtrlComboBox_SetCurSel($cmb020, 0)

Local $btn010 = GUICtrlCreateButton('My Freak"in Button', 20, 360, 360, 20)
GUICtrlSetState($btn010, $gui_focus)

GUISetState()

While 1
    Switch GUIGetMsg()
        Case $gui_event_close
            Exit
        Case $btn010
            MsgBox(0, '', GUICtrlRead($cmb010))
    EndSwitch
WEnd

kylomas

edit: corrected sre pattern

edit2: File used for example output.txt

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

Link to comment
Share on other sites

I think it is working right. I was able to test it on the machine I collected the output.txt file from and the data appears proper. I will test more this week as I hope to have a couple new boxes in over the next few days. Thank you for the help I really appreciate it. :D

Link to comment
Share on other sites

Sorry for the late appearance, but have you tried using Run with StdoutRead? You can also use my Process UDF which should make things simple by consolidating all into a single line:

Local $sOutput = _Process_RunCommand($PROCESS_RUNWAIT, @ComSpec & ' /c sqlcmd -Lc)

; $sOutput should contain the complete output of the `sqlcmd -Lc` command. _Process_RunCommand runs an executable and captures it output and returns it to $sOutput

 

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

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