How reveive error message?

General discussion for topics related to the FreeBASIC project or its community.
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

well but that is set of compiler messages
this program actually cannot receive error message
right ?
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

or
can i use buffer = GetCommandLine ()
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How reveive error message?

Post by dodicat »

Hi aurelVZAB
My little program will receive error messages if the string path includes path to compiler + space+path to a .bas file
example

Code: Select all

 
#Include Once "windows.bi"


Dim Shared As zString * 1024 path="C:\Users\Computer\Desktop\fb\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\fbc64.exe" 'compiler
                             path+=" "
                             path+="C:\Users\Computer\Desktop\fb\code\allbas\argand.bas"                     'source code


Declare Function fb_Set_Font (Font As String,Size As Integer,Bold As Integer=0,Italic As Integer=0,Underline As Integer=0,StrikeThru As Integer=0) As HFONT
Declare Function pipeout(s As String) As String

Declare Function main As Long
End main




Function WndProc(hWnd As HWND, msg As UINT, wParam As WPARAM, lParam As LPARAM) As LRESULT
    Static As hwnd ebox,btn
    Select Case msg
    
    Case WM_CREATE
        btn=CreateWindowEx(NULL,"button", "compiler", WS_VISIBLE Or WS_CHILD , 0,20,60,40, hwnd, Cast(Any Ptr,1), NULL, NULL) 
        ebox= CreateWindowEx(NULL,"edit", "", WS_VISIBLE Or WS_CHILD Or WS_VSCROLL Or WS_HSCROLL Or WS_Border Or ES_MULTILINE Or ES_AUTOVSCROLL , 0,350, 750, 200, hwnd,0, NULL, NULL) 
        Dim As HFONT   f1=fb_Set_Font("Courier new",10,,true),f2=fb_Set_Font("times new roman",10,,false)
        SendMessage(ebox,WM_SETFONT,Cast(WPARAM,f1),0)
        SendMessage(btn ,WM_SETFONT,Cast(WPARAM,f2),0)
        
    Case WM_COMMAND
    If Loword(wParam) =1 Then
         Var t=Timer
       var m=pipeout(path)
       if instr(m," error ")=0 then m+="Success, compiled in "+str(timer-t)+" seconds"
        setwindowtext(ebox,m)
    End If
    
    
   Case WM_CLOSE
    PostQuitMessage(NULL)
   End Select

Return DefWindowProc(hWnd, msg, wParam, lParam)
End Function

Function MAIN As Long
    ' Create  window class:
    Dim As WNDCLASS wcls
    Function=0
    With wcls
        .style      = CS_HREDRAW Or CS_VREDRAW
        .lpfnWndProc  = @WndProc
        .hInstance    = GetModuleHandle(NULL)
        .hIcon      = LoadIcon(NULL, IDI_APPLICATION)
        .hCursor      = LoadCursor(NULL, IDC_ARROW)
        .hbrBackground  = GetStockObject(WHITE_BRUSH)
        .lpszMenuName  = NULL
        .lpszClassName  = Strptr("WindowClass")
    End With
    
    If RegisterClass(@wcls) = FALSE Then
        MessageBox(NULL, "RegisterClass('WindowClass') FAIL!", "Error!", MB_OK Or MB_ICONERROR)
        End
    End If
    
    'mainwindow
    CreateWindowEx(NULL, "WindowClass", "Some editor", WS_OVERLAPPEDWINDOW Or WS_VISIBLE, 100, 100, 800, 600, NULL, NULL, NULL, NULL)
    
    Dim As MSG uMsg
    While GetMessage(@uMsg, NULL, NULL, NULL) <> FALSE
        TranslateMessage(@uMsg)
        DispatchMessage(@uMsg)
    Wend
End Function

Function fb_Set_Font (Font As String,Size As Integer,Bold As Integer,Italic As Integer,Underline As Integer,StrikeThru As Integer) As HFONT
    Dim As HDC hDC=GetDC(HWND_DESKTOP)
    Dim As Integer CyPixels=GetDeviceCaps(hDC,LOGPIXELSY)
    ReleaseDC(HWND_DESKTOP,hDC)
    Return CreateFont(0-(Size*CyPixels)/72,0,0,0,Bold,Italic,Underline,StrikeThru,ANSI_CHARSET _
    ,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,Font)
End Function

Function pipeout( s As String) As String
    Var f=Freefile
    Dim As String tmp
    Open Pipe s For Input As #f 
    s=""
    Do Until Eof(f)
        Line Input #f,tmp
        s+=tmp+Chr(13,10)
    Loop
    Close #f
    Return s
End Function 


 
If there is an error in the .bas file it will show, otherwise a success message will show.
I get no warnings here running the code (Win 10, fb 1.09.0 and fb 1.10.0)
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: How reveive error message?

Post by srvaldez »

very good dodicat :)
I have one question, why the following code ?

Declare Function main As Long
End main

I would expect that main would not get executed yet it is, btw in your present example end is not needed, at least I think so
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How reveive error message?

Post by dodicat »

srvaldez
Since main is a function returning 0, end main is OK.
It just returns 0 to the system after running main
But just main would do.
srvaldez
Posts: 3373
Joined: Sep 25, 2005 21:54

Re: How reveive error message?

Post by srvaldez »

dodicat, I rarely use End so I forgot that End can have an integer argument
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

OK dodicat
I will try again
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

dodicat
i tested with proper paths
and nothing ..simply not work
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How reveive error message?

Post by dodicat »

Hi aurelVZAB
I put
aurelVZAB
near the top of my argand.bas file
(A deliberate error)
here was my compiler output
C:\Users\Computer\Desktop\fb\code\allbas\argand.bas(3) error 42: Variable not declared, aurelVZAB in 'aurelVZAB'
With no deliberate error I get
Success, compiled in 0.350426900000457 seconds.

If you are using another compiler then the
if instr(m," error ")=0 then m+="Success, compiled in "+str(timer-t)+" seconds"
might not apply.
I tested with freepascal, it was OK.
For some reason C++ sends errors to the console and not the window, I will have to investigate.
Ed Davis
Posts: 37
Joined: Jul 28, 2008 23:24

Re: How reveive error message?

Post by Ed Davis »

dodicat wrote: Jan 17, 2023 10:10 For some reason C++ sends errors to the console and not the window, I will have to investigate.
g++ writes warnings/errors to stderr, so you'll need to capture that also.
Ed Davis
Posts: 37
Joined: Jul 28, 2008 23:24

Re: How reveive error message?

Post by Ed Davis »

aurelVZAB wrote: Jan 17, 2023 9:15 dodicat
i tested with proper paths
and nothing ..simply not work
Works fine for me here.
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

dodicat

can we agree in one thing?

I need to capture message from fbc.exe ....not from gcc
do i have right ?
dodicat
Posts: 7976
Joined: Jan 10, 2006 20:30
Location: Scotland

Re: How reveive error message?

Post by dodicat »

You could try this method, using a temp file, srvaldez suggested this back a bit.

Code: Select all

#Include Once "windows.bi"

'freeconsole
Dim Shared As zString *1024   path="C:\Users\Computer\Desktop\fb\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\fbc64.exe" 'compiler
                              path+=" "
                              path+="C:\Users\Computer\Desktop\fb\code\allbas\argand.bas"                     'source code

Declare Function fb_Set_Font (Font As String,Size As Integer,Bold As Integer=0,Italic As Integer=0,Underline As Integer=0,StrikeThru As Integer=0) As HFONT
Declare Function Load(s As String) As String
Declare Function main As Long
End main




Function WndProc(hWnd As HWND, msg As UINT, wParam As WPARAM, lParam As LPARAM) As LRESULT
    Static As hwnd ebox,btn
    Select Case msg
    
    Case WM_CREATE
        btn=CreateWindowEx(NULL,"button", "compiler", WS_VISIBLE Or WS_CHILD , 0,20,60,40, hwnd, Cast(Any Ptr,1), NULL, NULL) 
        ebox= CreateWindowEx(NULL,"edit", "", WS_VISIBLE Or WS_CHILD Or WS_VSCROLL Or WS_HSCROLL Or WS_Border Or ES_MULTILINE Or ES_AUTOVSCROLL , 0,350, 750, 200, hwnd,0, NULL, NULL) 
        Dim As HFONT   f1=fb_Set_Font("Courier new",10,,true),f2=fb_Set_Font("times new roman",10,,false)
        SendMessage(ebox,WM_SETFONT,Cast(WPARAM,f1),0)
        SendMessage(btn ,WM_SETFONT,Cast(WPARAM,f2),0)
        
    Case WM_COMMAND
    If Loword(wParam) =1 Then
         Var t=Timer
       shell path+ " >tempout.txt"
       var m=Load("tempout.txt")
       kill "tempout.txt"
       if instr(m," error ")=0 then m+="Success, compiled in "+str(timer-t)+" seconds"
        setwindowtext(ebox,m)
    End If
    
    
   Case WM_CLOSE
    PostQuitMessage(NULL)
   End Select

Return DefWindowProc(hWnd, msg, wParam, lParam)
End Function

Function MAIN As Long
    ' Create  window class:
    dim WND_CLASS_NAME  as string 
    WND_CLASS_NAME ="WindowClass"
    Dim As WNDCLASS wcls
    Function=0
    With wcls
        .style      = CS_HREDRAW Or CS_VREDRAW
        .lpfnWndProc  = @WndProc
        .hInstance    = GetModuleHandle(NULL)
        .hIcon      = LoadIcon(NULL, IDI_APPLICATION)
        .hCursor      = LoadCursor(NULL, IDC_ARROW)
        .hbrBackground  = GetStockObject(WHITE_BRUSH)
        .lpszMenuName  = NULL
        .lpszClassName = strptr (WND_CLASS_NAME)
    End With
    
    If RegisterClass(@wcls) = FALSE Then
        MessageBox(NULL, "RegisterClass('WindowClass') FAIL!", "Error!", MB_OK Or MB_ICONERROR)
        End
    End If
    
    'mainwindow
    CreateWindowEx(NULL, "WindowClass", "Some editor", WS_OVERLAPPEDWINDOW Or WS_VISIBLE, 100, 100, 800, 600, NULL, NULL, NULL, NULL)
    
    Dim As MSG uMsg
    While GetMessage(@uMsg, NULL, NULL, NULL) <> FALSE
        TranslateMessage(@uMsg)
        DispatchMessage(@uMsg)
    Wend
End Function

Function fb_Set_Font (Font As String,Size As Integer,Bold As Integer,Italic As Integer,Underline As Integer,StrikeThru As Integer) As HFONT
    Dim As HDC hDC=GetDC(HWND_DESKTOP)
    Dim As Integer CyPixels=GetDeviceCaps(hDC,LOGPIXELSY)
    ReleaseDC(HWND_DESKTOP,hDC)
    Return CreateFont(0-(Size*CyPixels)/72,0,0,0,Bold,Italic,Underline,StrikeThru,ANSI_CHARSET _
    ,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,DEFAULT_QUALITY,FF_DONTCARE,Font)
End Function

Function Load( fname As String) As String
    Var f=Freefile
    Dim As String tmp,s
    Open fname For Input As #f 
    Do Until Eof(f)
        Line Input #f,tmp
        s+=tmp+Chr(13,10)
    Loop
    Close #f
    Return s
End Function 



 
If you have no success try
shell path+ " 2>tempout.txt"
in line 31.
Tested freebasic, freepascal, G++
With G++ I have to use shell path+ " 2>tempout.txt"
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

Unfortunatlly i can't find in Jose CSED_FB ..
or Vanya IDE
or XusinBoy IDE
or KuanHsu fbPoseidon

how they capture fbc messages ...
i found something about CreateProces ..etc ..etc..
aurelVZAB
Posts: 666
Joined: Jul 02, 2008 14:55
Contact:

Re: How reveive error message?

Post by aurelVZAB »

I found something in Vanya IUP IDE
and looking to me very complicated :

Code: Select all

If CreatePipe(@hChildRead, @hChildWrite, @sa, NULL)  Then
		
		If SetHandleInformation(hChildRead, HANDLE_FLAG_INHERIT, NULL) Then
			   
			   Dim pi As PROCESS_INFORMATION
            
            Dim si As STARTUPINFO
			   
			   si.cb = SizeOf(STARTUPINFO)
			   
			   si.hStdError = hChildWrite   
			   
			   si.hStdOutput = hChildWrite  
			   
			   si.dwFlags = STARTF_USESTDHANDLES	
			   			
			   If CreateProcess( pszCMD ,pszParamCMD,NULL,NULL,TRUE,CREATE_NO_WINDOW,NULL,NULL,@si,@pi) Then		   	
			   	
			   	CloseHandle(hChildWrite)
			   	
			   	Do
			   	
				   	If ReadFile(hChildRead, @szBuffer, 1000, @iReadBytes, NULL) Then
				   		
				   		*pszSavedInfo &= Left(szBuffer , iReadBytes)
				   		
				   	Else
				   		
				   		Exit Do
				   		
				   	EndIf
			   	
			   	Loop
			   	
	           	CloseHandle(hChildRead)
	           	
			   	CloseHandle( pi.hProcess )
			   	
      			CloseHandle( pi.hThread )
      			
			   EndIf
			
		EndIf 
Post Reply