accessing the CLI in a prog - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Help Me! (https://qb64phoenix.com/forum/forumdisplay.php?fid=10) +---- Thread: accessing the CLI in a prog (/showthread.php?tid=2416) Pages:
1
2
|
accessing the CLI in a prog - PhilOfPerth - 01-31-2024 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 ?) RE: accessing the CLI in a prog - SMcNeill - 01-31-2024 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. RE: accessing the CLI in a prog - bplus - 01-31-2024 Like this? RE: accessing the CLI in a prog - TerryRitchie - 01-31-2024 (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. RE: accessing the CLI in a prog - PhilOfPerth - 01-31-2024 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. RE: accessing the CLI in a prog - SMcNeill - 01-31-2024 Code: (Select All)
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. 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. RE: accessing the CLI in a prog - GareBear - 01-31-2024 To run this in linux console do this: Code: (Select All) $Console RE: accessing the CLI in a prog - bplus - 01-31-2024 @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. RE: accessing the CLI in a prog - GareBear - 01-31-2024 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. RE: accessing the CLI in a prog - SMcNeill - 01-31-2024 $Console:Only doesn't work in Linux? What flavor and version of Linux are you running? |