Author Topic: Using BC.EXE with files in an ADS  (Read 729 times)

JoeC4281

  • Newbie
  • *
  • Posts: 23
    • View Profile
Using BC.EXE with files in an ADS
« on: February 06, 2023, 12:18:25 PM »
I use JPSoftware's TakeCommand Console when working from the command line.

I have been using TCC .BTM files to store source code in Alternate Data Streams, which I can then execute.

I have no problem executing a VBScript from an ADS, for example, test.btm contains;
Code: [Select]
type <<- endtext > %_batchname:testvbs.vbs
WScript.Echo Date
endtext

cscript.exe //nologo %_batchname:testvbs.vbs

...which produces...

Code: [Select]
R:\>test.btm
type <<- endtext > R:\test.btm:testvbs.vbs
cscript.exe //nologo R:\test.btm:testvbs.vbs
2023-02-06

However, BC.EXE does not seem to recognize an ADS file (test.btm:test.bas);

Code: [Select]
@setlocal
@echo off

if exist test.bas del /q test.bas
if exist test.c   del /q test.c

Gosub CreateBCXCode
type %_batchname:test.bas
call "C:\Program Files\BCX791\64-Bit\bc.exe" %_batchname:test.bas -m -z -q
iff exist test.c then
  call "E:\Program Files\tcc\tcc.exe" -run test.c
else
  echo test.c does not exist
endif
endlocal
quit

:CreateBCXCode
type <<- endtext > %_batchname:test.bas
#include <stdio.h>
#include <stdlib.h>

dim kount as long
dim amount as double
for kount = 1 to 365
  amount=amount+(kount*.01)
next

Print amount
endtext
Return

...which produces...

Code: [Select]
E:\...\TakeCommandConsole>test.btm
#include <stdio.h>
#include <stdlib.h>

dim kount as long
dim amount as double
for kount = 1 to 365
amount=amount+(kount*.01)
next

Print amount
Error: Cannot Access File or File Not Found.
tcc: error: file 'test.c' not found

Thus, if it is possible, please make BC.EXE able to read from files in an ADS.

Also, BC.EXE cannot, using the -f option, output a file to an ADS;

Code: [Select]
E:\...\TakeCommandConsole>bc test.bas -m -z -q -f:test.btm:test.c
Error: Cannot Access File or File Not Found. $WRK$.TXT

Being able to output to an ADS file would also be welcome.

Note that Tiny C can read an ADS file. Example;
Code: [Select]

E:\...\TakeCommandConsole>"E:\Program Files\tcc\tcc.exe" -run test.btm:test.c
 667.95

Joe

Ref: https://jpsoft.com/products/tcc-cmd-prompt.html
Ref: https://jpsoft.com/help/filestreams.htm
Ref: https://bellard.org/tcc/

MrBcx

  • Administrator
  • Hero Member
  • *****
  • Posts: 2039
    • View Profile
Re: Using BC.EXE with files in an ADS
« Reply #1 on: February 06, 2023, 01:32:34 PM »
Joe,

In all honesty, I don't see myself putting any effort into this wish.

%_batchname:test.bas   is not a valid windows filespec.

And likewise,

-f:test.btm:test.c   ... test.btm:test.c  is not a valid windows filespec.

Think of it this way ...

OPEN "test.btm:test.bas" FOR OUTPUT AS #1
CLOSE #1

produces a file named "test.btm"

Perhaps someone with the TCC forum can advise you of a way to restructure your ADS?
 

JoeC4281

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Using BC.EXE with files in an ADS
« Reply #2 on: February 06, 2023, 03:23:29 PM »
I've made changes to my test.btm,
where I now copy the file from the ADS to a file,
use BC.EXE to translate the file,
copy the TEST.C file to the ADS of test.btm,
then use Tiny C to run the test.c from the ADS of test.btm

Code: [Select]
Gosub CreateBCXCode
type %_batchname:test.bas > test.bas
call "C:\Program Files\BCX791\64-Bit\bc.exe" test.bas -m -z -q

iff exist test.c then
  copy /q test.c %_batchname:test.c
else
  echo test.c does not exist
endif

iff exist %_batchname:test.c then
  call "E:\Program Files\tcc\tcc.exe" -run %_batchname:test.c
else
  echo Tiny C cannot find test.c
endif

if exist test.bas del /q test.bas
if exist test.c   del /q test.c

endlocal

It slows down the processing slightly,
but it allows me to keep my files all together in one place using ADS.

Code: [Select]
E:\...\TakeCommandConsole>dir /: *.btm

 Volume in drive E is New Volume   Serial number is 2c1e:6e61
 Directory of  E:\Documents\bcx\TakeCommandConsole\*.btm

2023-02-06  16:05             723  test.btm
                              155    test.bas:$DATA
                            6,506    test.c:$DATA
               7,384 bytes in 1 file and 0 dirs.    16,384 bytes allocated

The same thing under cmd.exe requires a different dir switch;

Code: [Select]
E:\Documents\bcx\TakeCommandConsole>dir /r test.btm
 Volume in drive E is New Volume
 Volume Serial Number is 2C1E-6E61

 Directory of E:\Documents\bcx\TakeCommandConsole

2023-02-06  04:21 PM               792 test.btm
                                   155 test.btm:test.bas:$DATA
                                 6,506 test.btm:test.c:$DATA
               1 File(s)            792 bytes

Joe


Robert

  • Hero Member
  • *****
  • Posts: 1190
    • View Profile
Re: Using BC.EXE with files in an ADS
« Reply #3 on: February 06, 2023, 03:42:25 PM »
Hi Joe:

I'm busy at the moment so I can't test your batch files, but does changing

Code: [Select]
call "C:\Program Files\BCX791\64-Bit\bc.exe" %_batchname:test.bas -m -z -q
to

Code: [Select]
call "C:\Program Files\BCX791\64-Bit\bc.exe" -m -z -q < %_batchname:test.bas
adding the < redirection symbol to the call,

allow BCX to take the stdin?

JoeC4281

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Using BC.EXE with files in an ADS
« Reply #4 on: February 06, 2023, 05:32:54 PM »
Hello Robert,
  Thankyou for the suggestion, but unfortunately, STDIN re-direction does not work with BC.EXE

  However, there is the -o option, which sends a copy of the generated C code to STDOUT, thus;

Code: [Select]
call "C:\Program Files\BCX791\64-Bit\bc.exe" test.bas -m -z -q -o > %_batchname:test.c
  eliminates the need to copy test.c to test.btm:test.c

Thanks!

Joe