0

I've been doing some mucking around with DOSbox lately, and one particular task I've been doing is setting up a series of batch files for calling things so that I can save a few cds. A typical .bat file might look like the following:

cd wolf3d
wolf3d -goobers
cd ..

One thing that's become a bit annoying is the lack of a built-in text editor that I can use, such as pico/nano. That said, I do have QBASIC installed, so one option I was considering was setting up so I could do a call such as the following:

nano filename.bat

and it would open up the file in QBASIC.

I've done a bit of reading on how batch scripting works, and it appears that just adding a %1 to the script should suffice, such as the following:

cd qbasic
qbasic %1
cd ..

What ends up happening, however, is if I type in, say nano nano.bat so I can edit the batch file, it ends up opening up a new, blank nano.bat file instead.

I've tried to look up what I'm missing here, but this seems to be a bit too arcane to locate easily. Can anyone point out what's missing here?

Thanks!

Kaji
  • 249
  • DOS and Windows cmd are not the same thing. Hence the many things are also different https://scalibq.wordpress.com/2012/05/23/the-windows-command-prompt-is-not-a-dos-prompt/ – phuclv Apr 04 '17 at 03:34
  • 1
    If you change the current directory in the batch you have to supply drive:\path\name.ext as an argument, otherwise Qbasic can't find the file and creates a new one in the now current folder – LotPings Apr 04 '17 at 10:09
  • @LotPings When calling it, I've been using the path relative to the script, figuring that even though there's a cd in the file it would still catch the right path when getting the initial variable value. So I guess you're suggesting something like qbasic ..\%1 for the second line? I'm not in a place to test that right this moment, but once I get back to my desk I'll give it a shot. It definitely makes a lot of sense, now that you point it out. – Kaji Apr 04 '17 at 13:25
  • @LotPings That did it! If you could please repost your comment as an answer, I'll accept it. – Kaji Apr 04 '17 at 13:56

2 Answers2

1

To elaborate a bit more as in my comment:

  • If passing a relative path as an argument to a batch which itself changes the current folder will fail if the pass isn't relative to the new folder.
  • Alternatively pass an absolute pass
  • or don't change the current folder if not absolutely necessary. Qbasic is a standalone .exe file which can be somewhere reachable via the path. To use it as an editor there is an /Editor option (just checked it in VDOS Plus - a DosBOX derivate)

So change your nano.bat to

@Qbasic.exe /Editor %1

provided Qbasic.exe is reachable via a folder in the path.

LotPings
  • 7,231
0

Try double percents ie %%1. Batch files in dos do not quite follow the same rules for parameters as their dos shell equivalents.

  • That ended up opening a blank %1.BAS file in QBASIC. I tried reducing it to just %1 and that produced NANO.BAT this time around, however it's a new blank file, instead of the one that we're trying to update. qbasic ../nano.bat, however, does open the file properly, if I want to first go into /qbasic. – Kaji Apr 04 '17 at 03:29
  • Funny that it's opening a file called nano.bas. Makes me wonder if %1 in dos box is not the first argument to the batch job but the name of the batch job itself. What happens if you use %2? – AlwaysLearning Apr 04 '17 at 03:32
  • Slight correction, it's creating a blank nano.baT, not .baS; my mistake in the opening post. Changing it to %2 results in no file being created, just like a simple qbasic launch. – Kaji Apr 04 '17 at 03:35