Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
accessing the CLI in a prog
#1
How does one access the C Prompt (CLI) from within a  QBPE programme? I don't see any functions like CMD or COMMAND, but I know it can be (and is) done frequently by members. I've tried to interpret what they did, with no success. How do I get to put Shell "c: dir" (and others) into my programme? (maybe another lesson about CLI access etc ?)
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
#2
Usually the easiest way is to juust pipe the results into a text file and then read it back into your program.

SHELL "c:\dir > temp.txt"         <-- this runs that shell command to C:\DIR 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

^And then something similar to the above will read that file and print the results to the screen.
Reply
#3
Like this?


Attached Files Image(s)
   
b = b + ...
Reply
#4
(01-31-2024, 01:31 AM)PhilOfPerth Wrote: (maybe another lesson about CLI access etc ?)
In the tutorial is a side lesson on the CLI located here:

https://www.qb64tutorial.com/lessoncli

Everything in that lesson can be applied with the SHELL statement as Steve has explained above.

Lesson 11 then expands on these concepts with QB64 CLI related statements.
New to QB64pe? Visit the QB64 tutorial to get started.
QB64 Tutorial
Reply
#5
Thanks, all. But I'm afraid I wasn't able to get what I needed from any of those replies. (yes, Terry, I read all of those tuts).
There are obviously huge holes in my knowledge in this area. This code:
Shell "c:\dir > temp.txt" '      <-- this runs that shell command to C:\DIR 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
returns a blank window.

shell "CMD" 
gives the c: prompt, which I can then use by entering that window and using DOS commands (e.g. dir c: ) to get the tree structure. 
 I'd like to do all of that from within my programme. I suspect it's  something to do with batch files, but I don't know how to run these from PE.
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
#6
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.
Reply
#7
To run this in linux console do this:

Code: (Select All)
$Console
Shell "ls > temp.txt" '      <-- this runs that shell command to ls to get a listing of the current directory, 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
This will work for linux console. SMcNeill, I hope you don't mind the changes I made here.- GareBear
Reply
#8
@GearBear do offer Linux advice! I don't use Linux (yet) but I am sure this is helpful to those that do.

Besides mnr seems to have gone in hibernation.
b = b + ...
Reply
#9
Thanks!, bplus.

I wasn't sure if I could get it to work. When I remove the " :Only " from the  $console command it works. It helps having both DOS and some linux commands for reference.
Reply
#10
$Console:Only doesn't work in Linux?   What flavor and version of Linux are you running?
Reply




Users browsing this thread: 2 Guest(s)