Where is Print output?
-
- Posts: 2
- Joined: Jan 28, 2021 19:46
Where is Print output?
Windows 10. Where should I see the result of Print?
I have the IDE, an upper pane with a vertical bar halfway across which does not appear to be significant. A lower pane 'Results Window"
Print "Hello World" compiles and runs but I cannot see where it is printed.
John
I have the IDE, an upper pane with a vertical bar halfway across which does not appear to be significant. A lower pane 'Results Window"
Print "Hello World" compiles and runs but I cannot see where it is printed.
John
Re: Where is Print output?
Code: Select all
Print "Hello World from FreeBASIC"
Sleep ' keep console open until user action
-
- Posts: 2
- Joined: Jan 28, 2021 19:46
Re: Where is Print output?
That's the answer, thank you. In the meantime I had discovered that if I ran the executable from DOS I could see the output.
Thanks again, John
Thanks again, John
Re: Where is Print output?
Something that I have noticed while learning the Win32API: If you compile for GUI and then use "print" statements, the output can be seen if you launch your program from a cygwin terminal, but not if you do so from a CMD window. The GUI part of your program runs as normal. It's useful for debugging.
Here's me experimenting with a vertical scroll bar attached to a text window:
/cygdrive/g/My_DOCS/FreeBasicProjects/TestScroll $ ./TestScroll.exe
yChar = 16 nDispLines= 18 VscrollPos@si= 0
yChar = 16 nDispLines= 18 VscrollPos@si= 0
You can also compile for console and then you get a GUI and a console window with your print output in it.
Here's me experimenting with a vertical scroll bar attached to a text window:
/cygdrive/g/My_DOCS/FreeBasicProjects/TestScroll $ ./TestScroll.exe
yChar = 16 nDispLines= 18 VscrollPos@si= 0
yChar = 16 nDispLines= 18 VscrollPos@si= 0
You can also compile for console and then you get a GUI and a console window with your print output in it.
Re: Where is Print output?
You can use puts if you
#include "crt.bi"
puts or printf always prints to the console.
#include "crt.bi"
puts or printf always prints to the console.
Re: Where is Print output?
Hi John,
You could also try the WriteFile API function. FreeBASIC's Print command is the best option to send the output to the console.
You could also try the WriteFile API function. FreeBASIC's Print command is the best option to send the output to the console.
Code: Select all
#include "windows.bi"
Public Function StdOut ( Zstr As Zstring Ptr) As Integer
Dim As HANDLE hOutput
Dim As DWORD bWritten
hOutput=GetStdHandle(STD_OUTPUT_HANDLE)
WriteFile(hOutPut,Zstr,lstrlen(ZStr),@bWritten,NULL)
Function=bWritten
End Function
Dim As String test
test="This is a test."
StdOut test
Re: Where is Print output?
While developing a GUI application, it is often useful to have a console, too, so that you can print debugging info.
Unfortunately *), most IDEs are unable to autodetect if there is a Sleep (without args) command at the end of the code; otherwise, they could keep the console window open until the user closes it, and we would not see once a month desperate posts by new members complaining that they don't see their "Hello World".
*) I write this for the numerous IDE developers in this forum ;-)
Unfortunately *), most IDEs are unable to autodetect if there is a Sleep (without args) command at the end of the code; otherwise, they could keep the console window open until the user closes it, and we would not see once a month desperate posts by new members complaining that they don't see their "Hello World".
*) I write this for the numerous IDE developers in this forum ;-)
-
- Site Admin
- Posts: 6323
- Joined: Jul 05, 2005 17:32
- Location: Manchester, Lancs
Re: Where is Print output?
Yeah, having the option to keep the window open after the program has finished is often useful. More reliable and cleaner than putting Sleep at the end of runnable code.
It was achievable in FBIDE by tweaking the Run command.
It was achievable in FBIDE by tweaking the Run command.
-
- Posts: 1002
- Joined: Jul 14, 2005 23:41
Re: Where is Print output?
WinFBE has a similar functionality. Under 'Environment Options', 'Compiler Setup', check the box "Run compiled programs using command window".
I believe I added this functionality based on a request from fxm way back in version 1.3.9 in July 2017. Hope this helps those who use WinFBE but may not be aware of this functionality.
I believe I added this functionality based on a request from fxm way back in version 1.3.9 in July 2017. Hope this helps those who use WinFBE but may not be aware of this functionality.
Re: Where is Print output?
Geany also does this by default with the text "Press any key to continue . . ."
-
- Posts: 789
- Joined: Jul 26, 2018 18:28
Re: Where is Print output?
I use this functionality too.
To do this, in the VisualFBEditor parameters in the Run item, I select cmd or PowerShell. At the end of debugging, it will not close without this parameter either.
To do this, in the VisualFBEditor parameters in the Run item, I select cmd or PowerShell. At the end of debugging, it will not close without this parameter either.
Re: Where is Print output?
In case somebody is interested in detecting console vs gui automatically, here are the strings I use in RichMasm:
Code: Select all
txGuess db "key", 0 ; Inkey, inkey, getkey but not GetKeyState
db "rint", 0 ; ok for print and Print
db "MemState", 0 ; console only macro
db "StdOut", 0
; db "Input$", 0 ; MasmBasic console input; ambiguous because there is Input$(#1...
db "deb 4", 0, 0 ; second zero marks end of console keywords
db "Print #", 0 ; print to file does not need a console
db "ntRtf", 0, "ntRtf", 0 ; same for a true printer
db "WM_", 0, "WM_", 0 ; 2*WM_COMMAND, WM_CHAR, WM_CREATE, WM_CLOSE
db "Box", 0 ; MessageBox, MsgBox
db "wMsg", 0
db "Gui", 0, "Gui", 0 ; 2xGuiImage, GuiControl etc
db "SendMessage", 0
db "CreateWindow", 0
db "GetMessage", 0
db "ShowWindow", 0
db "SW_", 0, "hW", 0 ; SW_xxx and hWnd or hWin
db "LoadI", 0 ; LoadIcon, LoadImage
db "dcSta", 0 ; dcStatic
db "Image", 0 ; typically found in graphics apps
db "WinMain", 0 ; Pelles C
db "Dlg", 0, 0 ; second zero is end marker
Re: Where is Print output?
Hello,
I have been testing FreeBASIC (1.09.0) on a Windows 11 (64-bit) system using the VisualFBEditor and in general I can run all of the GUI applications well after compiling, but the problem seem to come with I compile a console application like "hello.bas"
'' Default (hello.bas)
Print "Hello from FreeBASIC!"
Print "Press any key to continue..."
Sleep
When I try to run the output hello.exe it just goes to a newline with no output displayed. Furthermore it also is running in the background when viewed from the taskmanager.
I thought that it was due to the "Sleep" waiting for a key to be pressed, so then I killed the hello.exe task and tried a new version:
'' Version1 (hello.bas)
#include "crt.bi"
Print "Hello from FreeBASIC!"
but I still get the exact same results in that it also does not produce any output from the Print statement and is also continuously running in the background in the taskmanager.
I tried other versions of the same simple code both with/without:
#include "crt.bi"
but still the same exact results.
To check further, I also tries some other compiled examples from the FreeBASIC examples, like threads, and many others but the results are the same with no output and the applications do not exit so I have to kill them from the task manager.
This lead me to believe that there is some fundamental bug within FreeBASIC for Windows console (command prompt) applications.
Any thoughts or suggestions would be extremely helpful.
Thanks and have a good day.
I have been testing FreeBASIC (1.09.0) on a Windows 11 (64-bit) system using the VisualFBEditor and in general I can run all of the GUI applications well after compiling, but the problem seem to come with I compile a console application like "hello.bas"
'' Default (hello.bas)
Print "Hello from FreeBASIC!"
Print "Press any key to continue..."
Sleep
When I try to run the output hello.exe it just goes to a newline with no output displayed. Furthermore it also is running in the background when viewed from the taskmanager.
I thought that it was due to the "Sleep" waiting for a key to be pressed, so then I killed the hello.exe task and tried a new version:
'' Version1 (hello.bas)
#include "crt.bi"
Print "Hello from FreeBASIC!"
but I still get the exact same results in that it also does not produce any output from the Print statement and is also continuously running in the background in the taskmanager.
I tried other versions of the same simple code both with/without:
#include "crt.bi"
but still the same exact results.
To check further, I also tries some other compiled examples from the FreeBASIC examples, like threads, and many others but the results are the same with no output and the applications do not exit so I have to kill them from the task manager.
This lead me to believe that there is some fundamental bug within FreeBASIC for Windows console (command prompt) applications.
Any thoughts or suggestions would be extremely helpful.
Thanks and have a good day.
Re: Where is Print output?
Something strange as a follow up on this.
It seems that when I use the VisualFBEditor IDE to build and run the default "hello.bas" then the resulting "hello.exe" does not produce any output and hangs in the task manager.
But when I tried the exact same "hello.bas" with the FBIde environment then things work just as expected and also other console application work both from within the environment as well as when I run the new FBIde resulting exe from a command prompt.
Just maybe there is something strange in the way that the VisualFBEditor is building the EXE.
Cheers
It seems that when I use the VisualFBEditor IDE to build and run the default "hello.bas" then the resulting "hello.exe" does not produce any output and hangs in the task manager.
But when I tried the exact same "hello.bas" with the FBIde environment then things work just as expected and also other console application work both from within the environment as well as when I run the new FBIde resulting exe from a command prompt.
Just maybe there is something strange in the way that the VisualFBEditor is building the EXE.
Cheers
Re: Where is Print output?
One more update.
Seems like the WinFBE IDE also works well.
I am now guessing that there may be something going on with the VisualFBEditor IDE since this one does not seem to work while the others do.
Cheers and have a good weekend.
Seems like the WinFBE IDE also works well.
I am now guessing that there may be something going on with the VisualFBEditor IDE since this one does not seem to work while the others do.
Cheers and have a good weekend.