How reveive error message?
Re: How reveive error message?
sorry dodicat
in my investigation i miss to check your latest code:
it looks that work but work if i click button
https://aurelsoft.ucoz.com/Compiler_msg.png
in my investigation i miss to check your latest code:
it looks that work but work if i click button
https://aurelsoft.ucoz.com/Compiler_msg.png
Re: How reveive error message?
I agree. Using CreatePipe can get pretty involved.
I think the best bets are:
* as suggested earlier by srvaldez and dodicat, use the shell command to run the compiler, and redirect the output to a temp file. Then just load the temp file.
* or, get the O2 guy (Charles) to create a "pipe" library routine for O2, and then you could use that.
Re: How reveive error message?
Hi Edor, get the O2 guy (Charles) to create a "pipe" library routine for O2, and then you could use that.
I really doubt that he is a interested,he refuse to do so many things i suggested him in the past .
Also this thing is some kind of hidden from users or less explained uhm..i will see
once again ..thanks dodicat & srvaldez
Re: How reveive error message?
@aurelVZAB
You are a funny guy.
You came on FBC's forum with a request. I gave you a solution. You refuse because it's using FBC.
I gave you a solution to use with O2 (dll). You seems to refuse, stuck with WIN Api.
I also told you to use createpipe API a pure Win api.
You found how to use it in Vanya's code but to complicated for you.
So what do you want ? something magic
You are a funny guy.
You came on FBC's forum with a request. I gave you a solution. You refuse because it's using FBC.
I gave you a solution to use with O2 (dll). You seems to refuse, stuck with WIN Api.
I also told you to use createpipe API a pure Win api.
You found how to use it in Vanya's code but to complicated for you.
So what do you want ? something magic
Re: How reveive error message?
@aurelVZAB
You are a funny guy.
You came on FBC's forum with a request. I gave you a solution. You refuse because it's using FBC.
I gave you a solution to use with O2 (dll). You seems to refuse, stuck with WIN Api.
I also told you to use createpipe API a pure Win api.
You found how to use it in Vanya's code but to complicated for you.
So what do you want ? something magic
I came to FBC forum. ..dude i am here from 2009
second ..who are you SARG...i see code here from dodicat ???....are you one with two nicknames
oups ...you france ...he scotland ..ouch sorry...
i have no problem to talk about o2 because version i used is last written in FB
and i don't want to use any external dll....i don't like dll-s
what kind of solution with o2 ..o2 is not just dll it is compiler in a dll form
yes i don't understand Vanya code very much....shame on me
something magic....no
i will search more ...yes
Re: How reveive error message?
No problem I was just a bit irritated.
As I'm very friendly. I'll post some code in fbc with only Win Api but you will have to translate in O2.
As I'm very friendly. I'll post some code in fbc with only Win Api but you will have to translate in O2.
Re: How reveive error message?
I _think_ it is perhaps a language issue, e.g., English vs. whatever his native tongue is (Croatian?). In any case, his English is much better than my Croatian!
I'll also take a stab at it:As I'm very friendly. I'll post some code in fbc with only Win Api but you will have to translate in O2.
Code: Select all
'based on: https://www.freebasic.net/forum/viewtopic.php?t=1016
#include "windows.bi"
#define BufferSize 1000
declare function GetConsoleOutput(shellcmd as string) as string
'assume gcc.exe is in the path, and foobad.c is in the current directory
print GetConsoleOutput("gcc.exe foobad.c")
function GetConsoleOutput(shellcmd as string) as string
dim si as STARTUPINFO
dim pi as PROCESS_INFORMATION
dim sa as SECURITY_ATTRIBUTES
dim as HANDLE hReadPipe, hWritePipe
dim as string sOutput = ""
dim sBuffer as ZString * BufferSize
dim bytesRead as long
sa.nLength = SizeOf(SECURITY_ATTRIBUTES)
sa.bInheritHandle = TRUE
sa.lpSecurityDescriptor = 0
if CreatePipe(@hReadPipe, @hWritePipe, @sa, 0) = 0 Then
Return "Error " + str(GetLastError()) + " on CreatePipe"
end if
si.cb = Len(STARTUPINFO)
si.dwFlags = STARTF_USESTDHANDLES Or STARTF_USESHOWWINDOW
si.hStdOutput = hWritePipe
si.hStdError = hWritePipe
si.wShowWindow = 0
if CreateProcess(0,shellcmd,NULL,NULL,TRUE,CREATE_NO_WINDOW,NULL,NULL,@si,@pi) = 0 Then
Return "Error " + str(GetLastError()) + " on CreateProcess"
end if
CloseHandle hWritePipe
while ReadFile(hReadPipe, @sBuffer, BufferSize, @bytesRead, 0) <> 0
sOutput += Left(sBuffer, bytesRead)
wend
CloseHandle pi.hProcess
CloseHandle pi.hThread
CloseHandle hReadPipe
Return sOutput
end Function
Re: How reveive error message?
Not a problem of language, rather not doing a small effort with all the different proposed solutions
As promised.
Code: Select all
#include "windows.bi"
'============= read pipe ================
private sub pipe_read(res as string,byref readhandle as handle)
#define BUFFER_SIZE 1000
dim as long vread,buffer_s=BUFFER_SIZE
dim as zstring *BUFFER_SIZE buffer
while 1
if ReadFile(readhandle, @buffer, buffer_s-1, @vread, NULL) then
buffer[vread+1]=0
res+=buffer
end if
if vread=0 then exit while
Wend
end sub
''========= open pipe and run fbc without a command window ==================
private function pipe_open(cmdl as string,byref pinfo as PROCESS_INFORMATION,byref readhandle as handle) as integer
Dim As Integer pclass
dim as HANDLE WriteHandle
dim as STARTUPINFO sinfo
' set up security attributes to allow pipes to be inherited
dim as SECURITY_ATTRIBUTES sa = type(sizeof(SECURITY_ATTRIBUTES), NULL, true)
' create the pipe
if (CreatePipe(@ReadHandle, @WriteHandle, @sa, 0)) =0 then
print "Create Pipe Failed, nothing done"
return -1 'error
end if
' establishing the START INFO structure for the child process
sinfo.cb = Len(sinfo)
sinfo.hStdinput = GetStdHandle(STD_INPUT_HANDLE)
' redirecting standard input to the write end of the pipe */
sinfo.hStdoutput = WriteHandle
sinfo.hStdError = WriteHandle
sinfo.dwFlags = STARTF_USESTDHANDLES
' don’t allow the child inheriting the read end of pipe */
SetHandleInformation(readHandle, HANDLE_FLAG_INHERIT, 0)
'Set the priority class NO_window is important to avoid a cmd window
pclass = NORMAL_PRIORITY_CLASS Or CREATE_NO_WINDOW
'create the child process inherit handles
if CreateProcess(null,StrPtr(cmdl),ByVal NULL,ByVal NULL, true, pclass,null, null, @sinfo, @pinfo)=0 then
print "prbm fbc child not created","error="+str(getlasterror)
closehandle(writeHandle) 'close the unused end of the pipe
closehandle(readHandle)
return -1 ''error
end if
closehandle(writeHandle) 'close the unused end of the pipe
end function
'========= close all ======
private sub pipe_close(pinfo as PROCESS_INFORMATION, readhandle as handle)
closehandle(readHandle) 'close the read of the pipe */
WaitForSingleObject(pinfo.hProcess,INFINITE) 'wait for the child/fbc to exit */
CloseHandle(pinfo.hProcess)
CloseHandle(pinfo.hThread)
end sub
'============================
dim as HANDLE readHandle
dim as PROCESS_INFORMATION pinfo
dim as string compil_res,cmdl
cmdl= "<path\fbc.exe> <name.bas>"
'========= main =============
if pipe_open(cmdl,pinfo,readhandle) = 0 then
pipe_read(compil_res,readhandle)
pipe_close(pinfo,readhandle)
print compil_res
else
print "there is a problem"
end if
print "terminated"
sleep
Last edited by SARG on Jan 19, 2023 8:10, edited 1 time in total.
Re: How reveive error message?
Before starting a project using files, solve the problem of spaces in filenames at the beginning (IMO)
Console output only.
Console output only.
Code: Select all
Var compilerpath="C:\Users\Computer\Desktop\fb\FreeBASIC-1.09.0-winlibs-gcc-9.3.0\fbc64.exe"
Var sourcepath="C:\Users\Computer\Desktop\newer folder\argand.bas"
Sub console(compiler As String,source As String)
If Instr(source," ") Then source=Chr(34)+source+Chr(34)
If Instr(compiler," ") Then compiler=Chr(34)+compiler+Chr(34)
Var num=Iif(Instr(source,".c")," 2>"," >")
var t=timer
Shell (compiler+" "+source+num+"testcode")
t=timer-t
Shell "type testcode"
Var f=Freefile,txt="",L=0
Open "testcode" For Binary As #f
L=Lof(f)
If L>0 Then
txt = String(L,0)
Get #f, , txt
End If
Close #f
txt=" "+txt
Kill "testcode"
If len(L)=0 Then Print "Problem":return
If Instr(txt," error")=0 Then Print "Compiled in " & t & " seconds" else print "FAILED OPERATION"
End Sub
console(compilerpath,sourcepath)
Print "_______________________"
console("gcc.exe","foobad.c")
Sleep
Code: Select all
C:\Users\Computer\Desktop\newer folder\argand.bas(3) error 42: Variable not declared, aurelVZAB in 'aurelVZAB'
FAILED OPERATION
_______________________
foobad.c: In function 'main':
foobad.c:5:9: error: unknown type name 'oops'
5 | oops
| ^~~~
foobad.c:6:17: error: expected declaration specifiers or '...' before string constant
6 | printf("%s\n","Hello World");
| ^~~~~~
foobad.c:6:24: error: expected declaration specifiers or '...' before string constant
6 | printf("%s\n","Hello World");
| ^~~~~~~~~~~~~
FAILED OPERATION
Re: How reveive error message?
Nice to see you back adeyblue.
All
The open pipe of freebasic won't accept gcc or g++ output to stderr.
Open Err might be a better choice for gcc/g++ output, but perhaps just writing to a temp file is OK, it does all streams.
All
The open pipe of freebasic won't accept gcc or g++ output to stderr.
Open Err might be a better choice for gcc/g++ output, but perhaps just writing to a temp file is OK, it does all streams.
Re: How reveive error message?
Thanks you adeyblue.
Problems reported should be fixed. See previous post.
Problems reported should be fixed. See previous post.
Re: How reveive error message?
Than you guys on trying and suggestions
thanks again
Code: Select all
type SECURITY_ATTRIBUTES
dword nLength
sys lpSecurityDescriptor
bool bInheritHandle
end type
type STARTUPINFO
dword cb
char* lpReserved
char* lpDesktop
char* lpTitle
dword dwX
dword dwY
dword dwXSize
dword dwYSize
dword dwXCountChars
dword dwYCountChars
dword dwFillAttribute
dword dwFlags
word wShowWindow
word cbReserved2
byte* lpReserved2
sys hStdInput
sys hStdOutput
sys hStdError
end type
type PROCESS_INFORMATION
sys hProcess
sys hThread
dword dwProcessId
dword dwThreadId
end type
Code: Select all
'////////////////////////////////////////////////////////////////////
'/// COMPILER OUTPUT FOR FREE BASIC ////
'////////////////////////////////////////////////////////////////////
Function GetConsoleOutput(shellcmd as string) as string
SECURITY_ATTRIBUTES sa
sys hReadPipe
sys hWritePipe
sa.nLength = sizeof SECURITY_ATTRIBUTES
sa.bInheritHandle = TRUE
sa.lpSecurityDescriptor = 0
'phReadPipe As Long, phWritePipe As Long, lpPipeAttributes As SECURITY_ATTRIBUTES, nSize As Long) As Long
'sys ok
if CreatePipe(@hReadPipe, @hWritePipe, @sa, 0)= 0
'if ok = 0
return "Error on CreatePipe"
end if
STARTUPINFO si
PROCESS_INFORMATION pi
% STARTF_USESHOWWINDOW = 0x00000001
% STARTF_USESTDHANDLES = &H100
si.cb = sizeof STARTUPINFO
si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW
si.wShowWindow = 0
si.hStdOutput = hWritePipe
si.hStdError = hWritePipe
% CREATE_NO_WINDOW = 0x08000000
sys ok
'ByVal lpApplicationName As String, ByVal lpCommandLine As String
ok=CreateProcess(null,strptr shellcmd, null, null, TRUE, CREATE_NO_WINDOW, null, null, @si, @pi)
if ok=0
return "Error on CreateProcess"
end if
CloseHandle hWritePipe
string OutBuf
string InBuf = nuls 16000
sys dwRead
while ReadFile(hReadPipe, strptr InBuf, len(InBuf), @dwRead, null) <> 0
OutBuf = OutBuf + mid(InBuf, 1, dwRead)
wend
CloseHandle pi.hProcess
CloseHandle pi.hThread
CloseHandle hReadPipe
return OutBuf
End Function
'--------------------------------------------------------------------------
sub CompilerOutput
' assuming gcc.exe is in the path, foobad.c in current dir, and has errors
string compPath,basPath,cOutput,msgText="" ,buff,statMsg
compPath = cdPath32 :' buff = buff + compPath + crlf
basPath = fName :' buff = buff + basPath + crlf : print buff
cOutput = compPath +" "+ basPath
msgText = GetConsoleOutput(cOutput)
' show message text in control ..todo?
if msgText =""
'MsgBox "Compiled Success!" ,"Compile Info"
statMsg = "Compiled Success!"
else
'MsgBox msgText ,"Compile Info"
statMsg = msgText
end if
SendMessage status,WM_SETTEXT,0, statMsg
end sub
'--------------------------------------------------------------------------
thanks again
Last edited by aurelVZAB on Mar 13, 2023 7:47, edited 1 time in total.
Re: How reveive error message?
and now with addition of multiline edit control