VOGONS


DOSBox Shell: Batch file problems

Topic actions

First post, by tricky_trev

User metadata
Rank Newbie
Rank
Newbie

There seems to be a problem with the way DOSBox handles batch files.

Possible problem areas: Drive cache, file open/close, or goto label function
shell.cpp, EmptyCache(); could be involved.

I have an application that is started by a batch file, and that application modifies this batch file when a menu item is clicked, then re-executes that batch file. The problem is that the menu item is not executed "now" but on the next menu selection, meaning that it is executed with a lag of 1 menu click.

In normal DOS, and with other DOS emulators it works fine.

Here is the simple batch file. Lines 5,6,7 are modified depending on the menu item.

@echo off
: start
PTSSHELL
SET COLORS=blue:white
echo leaving PTS-Shell ...
goto end
rem
goto start
: end

Any suggestions?

Trev.

Reply 3 of 27, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

our batch file parser keeps the file open during the execution of the bat file.

Water flows down the stream
How to ask questions the smart way!

Reply 4 of 27, by tricky_trev

User metadata
Rank Newbie
Rank
Newbie

yeah, i'd have to recompile the source of my program to add the rescan in but then it won't work in normal dos.

i've tried adding a rescan in the shell_batch.cpp but with no success. do you have an idea how to do it?

(my program has a shell that edits the batch file. that is - it keeps it open. not my idea but that's how it was done in the 80's as a way of "multitasking")

do you think it makes sense if we open and close the batch file before each line?

thanks,
trev.

Reply 5 of 27, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

I don't know how it went in real dos either.
I know that there is some interrupt that parses commandlines/batch file lines.
The started program from a batchfile doesn't get the filehandle of the batchfile. We now arange that by setting the non-inherit flag. It might be that the file was actually closed. Dunno.

Water flows down the stream
How to ask questions the smart way!

Reply 6 of 27, by tricky_trev

User metadata
Rank Newbie
Rank
Newbie

the only thing we don't know, is what exactly occured when this interrupt came....

does anyone know?

i really want to refine this shell_batch.cpp so it works like real DOS.

I don't know if rescan will help us here or not?

Reply 10 of 27, by tricky_trev

User metadata
Rank Newbie
Rank
Newbie

ok, so we know the problem. let's try to think of ways to get around it.

to me, it seems like the "old" unupdated file is still in memory. we have to add something to the line parser or reader (most likely the reader function) to refresh the cache or reload the file....

Reply 11 of 27, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Suppose you'd have to open the file before the DOS_ReadFile and close
it afterwards, and maintaining a line counter or something to seek to the
correct line before the DOS_ReadFile().

Reply 12 of 27, by tricky_trev

User metadata
Rank Newbie
Rank
Newbie

the goto does work how it should (it rereads the file). i have tested by editing the batch file outside of dosbox while the batch file is running, and the goto jump always picks up the edits immediately...

so i guess i have to implement something like this with a line pointer for the readfile..

any better ideas? i'll have a go at it...

Reply 13 of 27, by MiniMax

User metadata
Rank Moderator
Rank
Moderator

Line pointer? Better just a byte/character pointer.

DOSBox 60 seconds guide | How to ask questions
_________________
Lenovo M58p | Core 2 Quad Q8400 @ 2.66 GHz | Radeon R7 240 | LG HL-DT-ST DVDRAM GH40N | Fedora 32

Reply 14 of 27, by Kippesoep

User metadata
Rank Oldbie
Rank
Oldbie

The WinXP command prompt at least seems to use a byte/char pointer. I just tested with a batch file that changed the length of some lines above its execution point and it just dumps back to the prompt at that point (without any error message). If the lines are changed, but the length remains the same, execution continues.

Reply 15 of 27, by tricky_trev

User metadata
Rank Newbie
Rank
Newbie

i guess I shoulod use DOS_SeekFile() to return back to the position i was or?

I don't really understand this DOS_SEEK_SET part of the function. There are two other strings but it seems they are not used?

Reply 16 of 27, by wd

User metadata
Rank DOSBox Author
Rank
DOSBox Author

If DOS_ReadFile() returns true, in the 3rd parameter (&n) the number of
read characters is returned, so you can count them to maintain the position.

DOS_SeekFile() is used to set the position of the file, where you'll need the
DOS_SEEK_SET type (set position).
To query the file position you could also use DOS_SeekFile() with the
DOS_SEEK_CUR type and a zero offset, which should return the position
and does not change the file position.

Reply 17 of 27, by tricky_trev

User metadata
Rank Newbie
Rank
Newbie

So guys, the problem is solved with 3 lines of code in shell_batch.cpp

bool BatchFile::ReadLine(char * line) {
Bit8u c=0;Bit16u n=1;
Bit32u pos=0;
DOS_SeekFile(file_handle,&pos,DOS_SEEK_CUR); //bugfix: get current file position
DOS_SeekFile(file_handle,&pos,DOS_SEEK_SET); //bugfix: goto(set) file position to re-scan batch file for changes.

basically for every line of the batch file, i get the position, and then force a rescan by returning to the same position again....
any disputes about how i did it?

many many thanks for your great support!!!

trev

Reply 18 of 27, by tricky_trev

User metadata
Rank Newbie
Rank
Newbie

The only problem i see now is passing parameters (%2 %3 etc...) in call statements with "=" characters...

behaviour is different in real dos to DOSBox.... i suppose this is another thread 😀

Reply 19 of 27, by Qbix

User metadata
Rank DOSBox Author
Rank
DOSBox Author

Looking at the solution:

Isn't this a host level problem then ? I recall we have simalar code in dos_file:::read after a write
DOSBox itself does no caching of the data.

Water flows down the stream
How to ask questions the smart way!