From ae3323f630a6c35f73c49998cae17021effd7bcb Mon Sep 17 00:00:00 2001 From: "Scott A. Williams" Date: Sat, 18 Mar 2023 14:33:22 -0700 Subject: [PATCH 1/2] Initial prototype of output fix. --- qbsh.bas | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/qbsh.bas b/qbsh.bas index 5389c4e..01de752 100644 --- a/qbsh.bas +++ b/qbsh.bas @@ -150,7 +150,7 @@ buff_file$ = "/tmp/buff_qbsh_" + LTrim$(Str$(rndbuf)) If _FileExists(buff_file$) Then Kill buff_file$ End If -Shell "SHELL='" + SELFPATH$ + "'; " + cmd$ + " 2>&1 >" + buff_file$ +Shell "SHELL='" + SELFPATH$ + "'; " + cmd$ + " 2>&1 | tee /dev/stderr > " + buff_file$ Open buff_file$ For Binary As #1 x$ = Space$(LOF(1)) Get #1, , x$ From 850f55404fb078a1bedfc518b79a49613aa47e60 Mon Sep 17 00:00:00 2001 From: "Scott A. Williams" Date: Sat, 18 Mar 2023 15:19:26 -0700 Subject: [PATCH 2/2] Refactor CMDOUT to an io.bas function. --- lib/io.bas | 47 ++++++++++++++++++++++++++++++++--------------- qbsh.bas | 13 +------------ 2 files changed, 33 insertions(+), 27 deletions(-) diff --git a/lib/io.bas b/lib/io.bas index 1e83497..f39e8f6 100644 --- a/lib/io.bas +++ b/lib/io.bas @@ -3,29 +3,29 @@ 'listDir$ - Returns tab delimited file list of directory specified ' spec$ - Directory spec. Pass "" to get current directory FUNCTION listDir$ (spec$) - rndbuf = Rnd * 999999 - buff_file$ = "/tmp/buff_qbsh_" + LTrim$(Str$(rndbuf)) - If _FileExists(buff_file$) Then - Kill buff_file$ - End If - Shell "SHELL='" + SELFPATH$ + "'; dir -a " + spec$ + " 2>&1 >" + buff_file$ - Open buff_file$ For Binary As #1 - x$ = Space$(LOF(1)) - Get #1, , x$ - Close #1 - Kill buff_file$ - listDir$ = x$ + rndbuf = Rnd * 999999 + buff_file$ = "/tmp/buff_qbsh_" + LTrim$(Str$(rndbuf)) + If _FileExists(buff_file$) Then + Kill buff_file$ + End If + Shell "SHELL='" + SELFPATH$ + "'; $(which unbuffer) dir --color -a " + spec$ + " 2>&1 >" + buff_file$ + Open buff_file$ For Binary As #1 + x$ = Space$(LOF(1)) + Get #1, , x$ + Close #1 + Kill buff_file$ + listDir$ = x$ END FUNCTION 'listXDir$ - Give more detailed listing output than listDir$ ' spec$ - Directory spec. Pass "" to get current directory FUNCTION listXDir$ (spec$) - spec$ = "-l " + spec$ - listXDir$ = listDir$(spec$) + spec$ = "-l " + spec$ + listXDir$ = listDir$(spec$) END FUNCTION 'resolvePath$ - Expands ~ prefix to $HOME. Useful before doing filesystem operations -' RPATH$ - File-system path string +' RPATH$ - File-system path string FUNCTION resolvePath$(RPATH$) If RPATH$ = "~" Then RPATH$ = Environ$("HOME") + "/" @@ -35,3 +35,20 @@ FUNCTION resolvePath$(RPATH$) End If resolvePath = RPATH$ END FUNCTION + +'Subprocess$ - Run another process and return stdout +' cmd$ - Subprocess command to run on host +FUNCTION Subprocess$(cmd$) + rndbuf = Rnd * 999999 + buff_file$ = "/tmp/buff_qbsh_" + LTrim$(Str$(rndbuf)) + If _FileExists(buff_file$) Then + Kill buff_file$ + End If + Shell "SHELL='" + SELFPATH$ + "'; " + cmd$ + " | tee /dev/stderr > " + buff_file$ + Open buff_file$ For Binary As #1 + x$ = Space$(LOF(1)) + Get #1, , x$ + Close #1 + Kill buff_file$ + Subprocess$ = x$ +END FUNCTION diff --git a/qbsh.bas b/qbsh.bas index 01de752..5b9e5f4 100644 --- a/qbsh.bas +++ b/qbsh.bas @@ -145,18 +145,7 @@ Return 'Offload unhandled call to legacy system shell. qbsh is the only shell of the future. CMDOUT: -rndbuf = Rnd * 999999 -buff_file$ = "/tmp/buff_qbsh_" + LTrim$(Str$(rndbuf)) -If _FileExists(buff_file$) Then - Kill buff_file$ -End If -Shell "SHELL='" + SELFPATH$ + "'; " + cmd$ + " 2>&1 | tee /dev/stderr > " + buff_file$ -Open buff_file$ For Binary As #1 -x$ = Space$(LOF(1)) -Get #1, , x$ -Close #1 -Print x$ -Kill buff_file$ +stdOut$ = Subprocess$(cmd$) Return 'Delete a file path