Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
accessing the CLI in a prog
#11
(01-31-2024, 11:48 AM)SMcNeill Wrote:
Code: (Select All)
$Console:Only
Shell "dir c:\ > temp.txt" '      <-- this runs that shell command to DIR to get a listing of C:\, and then pipes the output to "temp.txt".
Open "temp.txt" For Input As #1
Do Until EOF(1)
    Line Input #1, text$
    Print text$
Loop

Give the above a try.  The issue with the blank screen was you specifying  "c: dir" and me just plugging it in by mistake.  There's no "dir.com", "dir.exe", or "dir.bat" file in the "c:\" directory, so no file to run and thus nothing to pipe.  Big Grin

By *just* using the DIR command, the system looks in the various paths and finds where that command is located, and then gives you a directory listing of C:\, as specified above.

Anytime you have issues with SHELL, test your command with $CONSOLE:ONLY.  Then your QB64 program will run in the console/terminal and you'll see the output before that shell window opens and closes instantly on you.  It's a great way to get those error messages and determine what the heck has gone wrong.

Ah, purrfic! Great work... short and sweet.  Big Grin
Thanks again to all.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#12
SMcNeill,

Here's what I run QB64PE 3.11.0 IDE with:

Kernel  - Linux/x86_64 6.6.10-76060610-generic Kernel
OS Name - Pop!_OS 22.04 LTS
OS Type - 64-bit
Windowing System - X11
Desktop Environment - GNOME 42.5
Terminal - gnome-terminal
Shell - bash 5.1.16

This OS is light enough to run on a Windows 7 machine along with a 1TB hard drive. The IDE does not lock up my system with this combination of OS and hard drive. I tried to include everything you might need to know.

When I ran it with the '$Console:Only'. It just compiled and no display with a OK to show it was finished. When I ran it with '$Console' it displayed the directory contents along with 'text.txt' in the listing and the usual 'Press any key to continue' when finished.

I think this is what you wanted to know what I have. If you need to know more let me know. - GareBear
Reply
#13
I think the problem comes from this:  
Quote:The IDE doesn't currently launch `$Console` programs in a terminal on Linux, so you just don't see anything unless you're watching the terminal you launched the IDE from.

Any chance you just wasn't looking in the right place to see the output? I'm not a Linux user, so I'm hoping that's all the issue is. If not, it'll be up to one of our Linux gurus to help sort out the issue and whatever the problem might be. Steve holds a lot of solutions in his old hat, but even he can't solve 100% of all issues all the time. Wink
Reply
#14
(02-01-2024, 01:24 AM)GareBear Wrote: SMcNeill,

Here's what I run QB64PE 3.11.0 IDE with:

Kernel  - Linux/x86_64 6.6.10-76060610-generic Kernel
OS Name - Pop!_OS 22.04 LTS
OS Type - 64-bit
Windowing System - X11
Desktop Environment - GNOME 42.5
Terminal - gnome-terminal
Shell - bash 5.1.16

This OS is light enough to run on a Windows 7 machine along with a 1TB hard drive. The IDE does not lock up my system with this combination of OS and hard drive. I tried to include everything you might need to know.

When I ran it with the '$Console:Only'. It just compiled and no display with a OK to show it was finished. When I ran it with '$Console' it displayed the directory contents along with 'text.txt' in the listing and the usual 'Press any key to continue' when finished.

I think this is what you wanted to know what I have. If you need to know more let me know. - GareBear
The issue is that the IDE doesn't spawn a new terminal to run your program in, so the output of the program will just appear in the terminal you started the IDE from (if you didn't start the IDE from a terminal, then the output may not be visible anywhere).

I believe we have a bug report on this, the IDE should really find and start a terminal for you (and warn you if it doesn't find one). That said if you open a terminal and run the compiled program that way then you will see the output you're expecting.

Also note that `$Console` and `$Console:Only` are very different, practically different commands. In your code `$Console` does nothing - it enables read/write from the console but there is still a graphical window. Additionally the graphical window is still the default destination for `PRINT` and friends so your program never uses console input/output and what you're seeing is just output on the graphical window, the same as all non-`$Console`.

When you use `$Console:Only`, the graphical window is disabled completely and your program reads/writes from/to the console by default. The lack of a graphical window is why you don't see anything.
Reply
#15
DSMan195276,

All I wanted to do is make a linux version of "CLI in a prog". You are right about no console display. It acted like a regular QB execution and no linux termial showed up. I thought the ':Only' in the $Console line was just a optional switch being I got it to "work".

Thanks for the help. Hope the bug is solved easily. - GareBear
Reply
#16
Using some of the bits and pieces I've learned from this forum, I built the small prog below.
Not earth-shattering, but I'm quite proud of it. It lets me see the contents of any of my drives.

Code: (Select All)
Screen _NewImage(1200, 820, 32)
SetFont: f& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", 24, "monospace"): _Font f&
fontsize = 24
_ScreenMove (_DesktopWidth - _Width) / 2, 86 ' centre display on screen
botline = _Height / _FontHeight - 2
Print "Drive letter (a to z)?"
Print "Esc to finish"
GetDrive: dl$ = UCase$(InKey$)
If dl$ = Chr$(27) Then System
If dl$ < "A" Or dl$ > "Z" Then GoTo GetDrive
comd$ = "dir " + dl$ + ":\ " + " > temp.txt"
Print comd$
Shell comd$
Open "temp.txt" For Input As #1
Do Until EOF(1)
    Line Input #1, text$
    Print text$
    If CsrLin > botline Then Print "More...": Sleep: Cls
Loop
Print "Press a key":: Sleep: Cls: Run
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply
#17
(02-01-2024, 06:17 AM)PhilOfPerth Wrote: Using some of the bits and pieces I've learned from this forum, I built the small prog below.
Not earth-shattering, but I'm quite proud of it. It lets me see the contents of any of my drives.
Code: (Select All)
Screen _NewImage(1200, 820, 32)
SetFont: f& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", 24, "monospace"): _Font f&
fontsize = 24
_ScreenMove (_DesktopWidth - _Width) / 2, 86 ' centre display on screen
botline = _Height / _FontHeight - 2
Print "Drive letter (a to z)?"
Print "Esc to finish"
GetDrive: dl$ = UCase$(InKey$)
If dl$ = Chr$(27) Then System
If dl$ < "A" Or dl$ > "Z" Then GoTo GetDrive
comd$ = "dir " + dl$ + ":\ " + " > temp.txt"
Print comd$
Shell comd$
Open "temp.txt" For Input As #1
Do Until EOF(1)
    Line Input #1, text$
    Print text$
    If CsrLin > botline Then Print "More...": Sleep: Cls
Loop
Print "Press a key":: Sleep: Cls: Run
And if you change the last line E.g

Print "Press a key": Sleep: Cls: Close #1: Kill ".\temp.txt": Run

Would you delete the TEMP file at the end .
Reply
#18
(02-01-2024, 04:28 PM)Steffan-68 Wrote:
(02-01-2024, 06:17 AM)PhilOfPerth Wrote: Using some of the bits and pieces I've learned from this forum, I built the small prog below.
Not earth-shattering, but I'm quite proud of it. It lets me see the contents of any of my drives.
Code: (Select All)
Screen _NewImage(1200, 820, 32)
SetFont: f& = _LoadFont("C:\WINDOWS\fonts\courbd.ttf", 24, "monospace"): _Font f&
fontsize = 24
_ScreenMove (_DesktopWidth - _Width) / 2, 86 ' centre display on screen
botline = _Height / _FontHeight - 2
Print "Drive letter (a to z)?"
Print "Esc to finish"
GetDrive: dl$ = UCase$(InKey$)
If dl$ = Chr$(27) Then System
If dl$ < "A" Or dl$ > "Z" Then GoTo GetDrive
comd$ = "dir " + dl$ + ":\ " + " > temp.txt"
Print comd$
Shell comd$
Open "temp.txt" For Input As #1
Do Until EOF(1)
    Line Input #1, text$
    Print text$
    If CsrLin > botline Then Print "More...": Sleep: Cls
Loop
Print "Press a key":: Sleep: Cls: Run
And if you change the last line E.g

Print "Press a key": Sleep: Cls: Close #1: Kill ".\temp.txt": Run

Would you delete the TEMP file at the end .

Yes, thanks Stefan. Two of my  many crimes are forgetting to close files, and to remove them.
Of all the places on Earth, and all the planets in the Universe, I'd rather live here (Perth, W.A.) Big Grin
Please visit my Website at: http://oldendayskids.blogspot.com/
Reply




Users browsing this thread: 1 Guest(s)