Log file reading and showing in dialog

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Log file reading and showing in dialog

Post by Identis » Thu Oct 27, 2016 10:38 am

Hello,

I want to read log file, find in it this "K:\import_export\" and show full line this this value from log to dialog memo or list and loop this log checking.

I tried different codes, but i'm new to macro and don't know what to do now :(

Please help.

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 247
  Top = 97
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Read_file'
  ClientHeight = 804
  ClientWidth = 431
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSButton1: tMSButton
    Left = 245
    Top = 8
    Width = 75
    Height = 25
    Caption = 'Browse'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object Edit1: TEdit
    Left = 64
    Top = 12
    Width = 161
    Height = 21
    TabOrder = 1
    Text = 'Failas'
  end
  object MSMemo1: tMSMemo
    Left = 32
    Top = 88
    Width = 369
    Height = 681
    TabOrder = 2
  end
  object MSButton2: tMSButton
    Left = 171
    Top = 53
    Width = 75
    Height = 25
    Caption = 'Start'
    DoubleBuffered = True
    ParentDoubleBuffered = False
    TabOrder = 11
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1

AddDialogHandler>Dialog1,MSButton1,OnClick,PerformBrowse
AddDialogHandler>Dialog1,MSButton2,OnClick,read
Show>Dialog1,r
SRT>PerformBrowse
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,TRUE
  GetDialogProperty>Dialog1,MSButton1,Filename,theFile
  SetDialogProperty>Dialog1,Edit1,Text,theFile
END>PerformBrowse

SRT>read
Let>k=1
While>line<>##EOF##
ReadLn>theFile,k,line
If>line=K:\import_export\,rodo
SRT>rodo


  SetDialogProperty>Dialog1,MSMemo1,text,line
  
  
END>rodo
endif
Let>k=k+1
EndWhile
  
END>read
Exit>0

Last edited by Identis on Fri Oct 28, 2016 4:42 am, edited 1 time in total.

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: Log file reading and showing in dialog

Post by JRL » Thu Oct 27, 2016 4:45 pm

I'm confused about what you want. It appears you have modified the "Dialog - File Browse Example.scp" that ships with Macro Scheduler. That files does what your post seems to be requesting. What am I missing?

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Re: Log file reading and showing in dialog

Post by CyberCitizen » Fri Oct 28, 2016 1:47 am

Ok from my understanding what your wanting is a dialog that will display the contents of a particular log file. This Dialog needs to update every so often to allow real-time monitoring of said log file. Is this correct?

Something like Trace32.exe from SCCM does.

If this is what your after, then it will be fairly easy to do with Macro Scheduluer.

Is there a reason your reading line by line instead of read file?
FIREFIGHTER

Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Re: Log file reading and showing in dialog

Post by Identis » Fri Oct 28, 2016 4:42 am

CyberCitizen wrote:Ok from my understanding what your wanting is a dialog that will display the contents of a particular log file. This Dialog needs to update every so often to allow real-time monitoring of said log file. Is this correct?

Something like Trace32.exe from SCCM does.

If this is what your after, then it will be fairly easy to do with Macro Scheduluer.

Is there a reason your reading line by line instead of read file?
Yes, I need realtime file monitoring and if macro finding this words: "K:\import_export\" then it will show full line from file in dialog list. I'm new to scheduler so I don't know how it's better to read all file or line by line.


For example log file looks like:

2016.10.27 03:52:32.554 - K:\import_export\Centrinių svarstyklių svoriai\2mikazy-HZT845-03.52.07-.csv
2016.10.27 03:52:32.554 - Command: TProgramDataBase.ImportWeights
2016.10.27 03:52:32.554 - Command: TProgramDataBase.ImportWeights
2016.10.27 03:52:32.556 - Request: TProgramDataBase.GetCarID ( CAR_NUMBER - 'HZT845' ) - DONE. Result -> '1257'
2016.10.27 03:52:32.557 - Request: TProgramDataBase.GetCarCardsID ( CAR_ID - '1257' ) - DONE. Result -> '1032; '
2016.10.27 03:52:32.559 - Command: UpdateCard_MinMax ( MIN_NETO - '3325', MAX_NETO - '3379', CARD_ADD_NUM1 - '27', ADD1 - '3352', MIN_BRUTO - '', MAX_BRUTO - '', CARD_ADD_NUM1 - '', ADD2 - '', where ID - '1032') - DONE
2016.10.27 03:53:02.558 - TWghtsImport.OnTimer
2016.10.27 03:53:11.982 - TVehicleImport.OnTimer
2016.10.27 03:53:11.982 - TDriverImport.OnTimer
2016.10.27 03:53:32.577 - TWghtsImport.OnTimer
2016.10.27 03:54:02.596 - TWghtsImport.OnTimer
2016.10.27 03:54:12.004 - TVehicleImport.OnTimer
2016.10.27 03:54:12.004 - TDriverImport.OnTimer
2016.10.27 03:54:32.615 - TWghtsImport.OnTimer
2016.10.27 03:55:02.633 - TWghtsImport.OnTimer
2016.10.27 03:55:12.026 - TVehicleImport.OnTimer
2016.10.27 03:55:12.026 - TDriverImport.OnTimer
2016.10.27 03:55:32.649 - TWghtsImport.OnTimer
2016.10.27 03:56:02.665 - TWghtsImport.OnTimer
2016.10.27 03:56:12.041 - TVehicleImport.OnTimer
2016.10.27 03:56:12.042 - TDriverImport.OnTimer
2016.10.27 03:56:32.681 - TWghtsImport.OnTimer
2016.10.27 03:57:02.696 - TWghtsImport.OnTimer
2016.10.27 03:57:12.057 - TVehicleImport.OnTimer
2016.10.27 03:57:12.057 - TDriverImport.OnTimer
2016.10.27 03:57:32.713 - TWghtsImport.OnTimer
2016.10.27 03:58:02.729 - TWghtsImport.OnTimer
2016.10.27 03:58:12.073 - TVehicleImport.OnTimer
2016.10.27 03:58:12.073 - TDriverImport.OnTimer
2016.10.27 03:58:32.744 - TWghtsImport.OnTimer
2016.10.27 03:58:32.765 - K:\import_export\Centrinių svarstyklių svoriai\VOLEIBOG-DBG635-03.58.07-.csv
2016.10.27 03:58:32.765 - Command: TProgramDataBase.ImportWeights
2016.10.27 03:58:32.765 - Command: TProgramDataBase.ImportWeights
2016.10.27 03:58:32.767 - Request: TProgramDataBase.GetCarID ( CAR_NUMBER - 'DBG635' ) - DONE. Result -> '57'
2016.10.27 03:58:32.768 - Request: TProgramDataBase.GetCarCardsID ( CAR_ID - '57' ) - DONE. Result -> '53; '
2016.10.27 03:58:32.770 - Command: UpdateCard_MinMax ( MIN_NETO - '3537', MAX_NETO - '3605', CARD_ADD_NUM1 - '34', ADD1 - '3571', MIN_BRUTO - '', MAX_BRUTO - '', CARD_ADD_NUM1 - '', ADD2 - '', where ID - '53') - DONE
2016.10.27 03:59:02.760 - TWghtsImport.OnTimer
2016.10.27 03:59:12.092 - TVehicleImport.OnTimer
2016.10.27 03:59:12.093 - TDriverImport.OnTimer


So if read file will find this "K:\import_export\", i want in dialog list see this all line:
2016.10.27 03:58:32.765 - K:\import_export\Centrinių svarstyklių svoriai\VOLEIBOG-DBG635-03.58.07-.csv

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Re: Log file reading and showing in dialog

Post by CyberCitizen » Fri Oct 28, 2016 5:00 am

What about running a command line like below via Macro Scheduler. Exporting the Output to a text file then reading that text file?

Find /N "K:\import_export\" TheFullPathToTheFileYouWantToSearch
FIREFIGHTER

Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Re: Log file reading and showing in dialog

Post by Identis » Fri Oct 28, 2016 5:05 am

CyberCitizen wrote:What about running a command line like below via Macro Scheduler. Exporting the Output to a text file then reading that text file?

Find /N "K:\import_export\" TheFullPathToTheFileYouWantToSearch
I think it's also good solution. But how can I make loop to check file real time, it's need to check file date_time or just check every 1s?

Thanks for Your help:)

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Re: Log file reading and showing in dialog

Post by CyberCitizen » Fri Oct 28, 2016 5:12 am

This was a quick knock up, I haven't included dialogs etc as they can take longer to put together etc But hopefully this gives you the idea of how it works.

Code: Select all

Let>MSG_HEIGHT=320
Let>MSG_WIDTH=500
Let>MSG_STAYONTOP=1
Let>MSG_CENTERED=1

Let>INPUT_BROWSE=1
Input>vFileToMonitor,Please Select The Log To Monitor,C:\MJ\Temp\TestReport.txt
Let>INPUT_BROWSE=0
Input>vSearchString,Please Enter Search String,K:\import_export\
Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Run>cmd /c Find "%vSearchString%" %vFileToMonitor% > %TEMP_DIR%Report.txt
ReadFile>%TEMP_DIR%Report.txt,vOutput
MDL>%vOutput%
In the find command (right after find) you can include /N to include the line number if wanted.

Regarding the loop you could use IfFileChanged to monitor it for changes etc. Just include a Wait>1 in the loop so it doesn't run thousands of times a second blowing out your memory usage.
FIREFIGHTER

Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Re: Log file reading and showing in dialog

Post by Identis » Fri Oct 28, 2016 5:20 am

CyberCitizen wrote:This was a quick knock up, I haven't included dialogs etc as they can take longer to put together etc But hopefully this gives you the idea of how it works.

Code: Select all

Let>MSG_HEIGHT=320
Let>MSG_WIDTH=500
Let>MSG_STAYONTOP=1
Let>MSG_CENTERED=1

Let>INPUT_BROWSE=1
Input>vFileToMonitor,Please Select The Log To Monitor,C:\MJ\Temp\TestReport.txt
Let>INPUT_BROWSE=0
Input>vSearchString,Please Enter Search String,K:\import_export\
Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Run>cmd /c Find "%vSearchString%" %vFileToMonitor% > %TEMP_DIR%Report.txt
ReadFile>%TEMP_DIR%Report.txt,vOutput
MDL>%vOutput%
In the find command (right after find) you can include /N to include the line number if wanted.

Regarding the loop you could use IfFileChanged to monitor it for changes etc. Just include a Wait>1 in the loop so it doesn't run thousands of times a second blowing out your memory usage.
Thanks mate. I will try Your solution.

Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Re: Log file reading and showing in dialog

Post by Identis » Fri Oct 28, 2016 5:54 am

CyberCitizen wrote:This was a quick knock up, I haven't included dialogs etc as they can take longer to put together etc But hopefully this gives you the idea of how it works.

Code: Select all

Let>MSG_HEIGHT=320
Let>MSG_WIDTH=500
Let>MSG_STAYONTOP=1
Let>MSG_CENTERED=1

Let>INPUT_BROWSE=1
Input>vFileToMonitor,Please Select The Log To Monitor,C:\MJ\Temp\TestReport.txt
Let>INPUT_BROWSE=0
Input>vSearchString,Please Enter Search String,K:\import_export\
Let>RP_WAIT=1
Let>RP_WINDOWMODE=0
Run>cmd /c Find "%vSearchString%" %vFileToMonitor% > %TEMP_DIR%Report.txt
ReadFile>%TEMP_DIR%Report.txt,vOutput
MDL>%vOutput%
In the find command (right after find) you can include /N to include the line number if wanted.

Regarding the loop you could use IfFileChanged to monitor it for changes etc. Just include a Wait>1 in the loop so it doesn't run thousands of times a second blowing out your memory usage.
I'm trying to get output from file to dialog list, but it's empty :( What I'm doing wrong?

after dialog and code im using:
Show>Dialog1,r
SetDialogProperty>Dialog1,MSListBox1,ListText,vOutput

but it's empty.

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Re: Log file reading and showing in dialog

Post by CyberCitizen » Fri Oct 28, 2016 5:57 am

Why a list box and not a memo box like the first script?
FIREFIGHTER

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Re: Log file reading and showing in dialog

Post by CyberCitizen » Fri Oct 28, 2016 6:06 am

Try This

Code: Select all

Dialog>Dialog1
object Dialog1: TForm
  Left = 251
  Top = 97
  HelpContext = 5000
  BorderIcons = [biSystemMenu]
  Caption = 'Read_file'
  ClientHeight = 305
  ClientWidth = 668
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = True
  ShowHint = True
  OnTaskBar = False
  PixelsPerInch = 96
  TextHeight = 13
  object MSButton1: tMSButton
    Left = 504
    Top = 8
    Width = 75
    Height = 25
    Caption = 'Browse'
    TabOrder = 0
    DoBrowse = False
    BrowseStyle = fbOpen
  end
  object Edit1: TEdit
    Left = 8
    Top = 4
    Width = 489
    Height = 21
    TabOrder = 1
    Text = 'Failas'
  end
  object MSMemo1: tMSMemo
    Left = 8
    Top = 40
    Width = 649
    Height = 257
    ScrollBars = ssBoth
    VertScrollBarStyles.ButtonSize = 16
    HorzScrollBarStyles.ButtonSize = 16
    TabOrder = 2
  end
  object MSButton2: tMSButton
    Left = 584
    Top = 8
    Width = 75
    Height = 25
    Caption = 'Start'
    TabOrder = 3
    DoBrowse = False
    BrowseStyle = fbOpen
  end
end
EndDialog>Dialog1
AddDialogHandler>Dialog1,MSButton1,OnClick,PerformBrowse
AddDialogHandler>Dialog1,MSButton2,OnClick,read
Show>Dialog1,r
SRT>PerformBrowse
  SetDialogProperty>Dialog1,MSButton1,DoBrowse,TRUE
  GetDialogProperty>Dialog1,MSButton1,Filename,theFile
  SetDialogProperty>Dialog1,Edit1,Text,theFile
END>PerformBrowse

SRT>read
  Let>RP_WAIT=1
  Let>RP_WINDOWMODE=0
  Run>cmd /c Find K:\import_export\ %theFile% > %TEMP_DIR%Report.txt
  ReadFile>%TEMP_DIR%Report.txt,vOutput
  DeleteFile>%TEMP_DIR%Report.txt
  SetDialogProperty>Dialog1,MSMemo1,text,%vOutput%
END>read
Exit>0
FIREFIGHTER

Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Re: Log file reading and showing in dialog

Post by Identis » Fri Oct 28, 2016 6:08 am

CyberCitizen wrote:Why a list box and not a memo box like the first script?
Changed to memo same thing.

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Re: Log file reading and showing in dialog

Post by CyberCitizen » Fri Oct 28, 2016 6:09 am

Try the code I posted above.
FIREFIGHTER

Identis
Junior Coder
Posts: 26
Joined: Fri Mar 27, 2015 11:26 am

Re: Log file reading and showing in dialog

Post by Identis » Fri Oct 28, 2016 6:25 am

CyberCitizen wrote:Try the code I posted above.
Tried and it's empty because something wrong with find command, Report.txt file is always empty, if I manually type something everything is ok and result is showed in memo.

User avatar
CyberCitizen
Automation Wizard
Posts: 721
Joined: Sun Jun 20, 2004 7:06 am
Location: Adelaide, South Australia

Re: Log file reading and showing in dialog

Post by CyberCitizen » Fri Oct 28, 2016 6:37 am

Ok most likely cause its dos I need to encapsulate it in quotes, on the train on my phone now, so can't assist until tomorrow now, busy tonight, not at home.

Sent from my GT-I9505 using Tapatalk
FIREFIGHTER

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts