Piping and redirection like Bash?

Started by bprlhe, August 05, 2023, 12:59:53

Previous topic - Next topic

bprlhe


bplus

Yeah! It was pretty cool how Basic worked with DOS back in the days before Windows came to dominate.

But that was when Windows graphics were agonizingly slow and text ran circles around Widows OS functionality.

Now days who wants to type 2 mile long paths (that are no longer restricted to 8 letters and no spaces let alone worry about case sensitivity) to a file?

If that old stuff appeals to you, go for it!
1 person likes this

bprlhe

Quote from: bplus on August 05, 2023, 16:28:18Yeah! It was pretty cool how Basic worked with DOS back in the days before Windows came to dominate.
But that was when Windows graphics were agonizingly slow and text ran circles around Widows OS functionality.
Now days who wants to type 2 mile long paths (that are no longer restricted to 8 letters and no spaces let alone worry about case sensitivity) to a file?
If that old stuff appeals to you, go for it!
I want to use SmallBASIC as an alternative to Bash and Python for automation tasks. The programs will run on Linux or Cygwin/MSYS2 on Windows.

bplus

You know our sb friend jsalai did a really nice file manager thing with sb some time ago 2-3 years?

I don't know if things changed that it still works like it did in Windows back then but it did some basic filing tasks that sound a little like you want to do. 

Maybe someone can dig around for that code? it was on old sb forum I think. I've lost at least 2 hard disks since I reviewed so pretty sure I don't have it any more.
1 person likes this

bplus

#4
BTW can't you do piping and redirection from the command prompt?

You can with Shell in QB64. I don't know about Linux but there is PowerShell too I think.

Does sb have similar sub/function built in?
1 person likes this

bprlhe

#5
Quote from: bplus on August 05, 2023, 17:15:38BTW can't you do piping and redirection from the command prompt?

You can with Shell in QB64.


The command prompt is Bash on Linux, which I want to use SmallBASIC as an alternative. Of course I could write a Bash script that call SmallBASIC when needed but what about get rid of Bash and write the entire script in SmallBASIC?

Note: I want to use SmallBASIC for two purposes. First is embed into C++ programs to provide scripting capability. Second is as an alternative to Bash and Python for automation tasks (that is always assume a Linux-like environment so you don't have to include Windows related things here).

bplus

#6
Looks like EXEC keyword is your ticket to running programs outside sb (and returning back to sb program).

If it works like Shell then that could be a way to pass switches, file parameters and such if the outside program is prepared to take those like most useful ones are.

So I think I answered my own question: does sb have Shell?

Therefore sb could run command prompt in Windows and the equivalent in Linux, bash?
1 person likes this

J7M

I'm using SmallBasic as a replacement for bash scripts. Use as the first line of your SB-Script "#! sbasic". Have sbasic (the console version) installed in your search path. Make the scrip executable. Now you can run it like a bash or a python script. Redirect the output into a file or piping to i.e. grep works fine. I have never tried redirect from a file to SB or piping to SB.

bprlhe

#8
Quote from: J7M on August 05, 2023, 20:48:20I'm using SmallBasic as a replacement for bash scripts. Use as the first line of your SB-Script "#! sbasic". Have sbasic (the console version) installed in your search path. Make the scrip executable. Now you can run it like a bash or a python script. Redirect the output into a file or piping to i.e. grep works fine. I have never tried redirect from a file to SB or piping to SB.
Do you ever launch external programs from the SmallBASIC script? The ability of Bash to redirect streams from one process to another (piping) and redirect streams to/from files is so powerful. As I said in the other thread, if SmallBASIC's RUN command captured both stderr and stdout, then how could I get only stderr or stdout if I don't need both of them? It doesn't offer the level of control needed to do such a thing as Bash. It's more like an improved version of C's `system` function.

bprlhe

Python offers various functions to call and manipulate external processes. What SmallBASIC currently offers is too limited, making it impossible to be an alternative to either Bash or Python.