Problem with variable Drive setup for XP/W98SE
Moderator: DosItHelp
Problem with variable Drive setup for XP/W98SE
Hi everyone ,
Pc SPEC:
Current OS WinXPSP3 working within CMD.EXE & I have also tried to use Command.com from CMD window. PC is Small-Form Factor Intel core i7 vPro with 8 gig ram usb non-wireless mouse setup on dual boot "grub for dos" non-bootsector dual boot mechanism with Q4OS Linux OS. I have portable Vbox installed off usb drive with Win98SE & ME
- I have tried googling for a similar problem without much luck
- I have not yet tried within W98SE Vbox but first it needs to work within XP first (possibly Win3.1?)
- I have tried to examine the script with echo on instead of echo off
- I have tried to break the script down into stages & stopped the script from deleting the temp files it makes to see what is within these temp bat files.
- Have tried to echo the variable upon completion to see if it is defined & the answer is no
Can someone shed some light on what I am doing wrong with a small elementary batch script that I am trying to compile. I'm sure it is something simple that I am missing & will KICK myself when I discover what but the problem has got me confounded.
The batch script (IF possible needs to work in XP as well as Win98SE [& a luxury would be Win3.1]) Here is the batch script with comments to try to explain what I am trying to do with the script?
@ECHO ON (Used to see whats going on with the batch script will @echo off when fixed)
SET DRV= (Used to clear any previous Drive: Vars so starting from fresh each time)
ECO.COM SET DRV=>T1.BAT (ECO.COM is a debug echo script that permits not having CRLF)
ECHO PROMPT $N:>T2.BAT ($N: is a Prompt for Drive: not $p$g standard prompt redirected to T2 temp bat
COPY T1.BAT+T2.BAT T3.BAT>NUL (Joins 2No temp bats to form third temp bat with copy)
CALL T3.BAT (Calls T3 temp bat with one line of SET code)
:: DEL T?.BAT (Deletes all three temp bats to cleanup)
ECHO Your Current Drive is %DRV% Tests if the variable is defined the answer is no)
pause (Pause is used to retain info on the screen when script completes)
T1.BAT has the following text therein SET DRV=
T2.BAT has the following text therein PROMPT $N:
T3.BAT lastly has this text before being called SET DRV=PROMPT $N:
Is the newline carriage return square box thingy on next line
Within the CMD window I get the following text:
Your Current Drive is <Nothing>
Press any key to continue . . . <cursor>
What this script is supposed to do is get the Drive: prompt into a variable e.g. "C:" (without quotes) but it ain't happening at my end? Some help would be appreciated, thanks in advance
P.S. Oh by the way & as feedback in respect of "How to get help for a batch script - quickly!" the links within the post do not work for me I am using Palemoon which is firefox browser on XP. Could someone check to see if its just me with my browser or are the links not going anywhere?
P.S2 - I have tried to establish this script from the command prompt. If for instance I type at the command prompt "PROMPT $N:" & hit the <ENTER> key this works manually typing it in manually however within batch it is failing, any ideas Please? I have also tried Echoing prompt & using a key-stuffer to simulate the <ENTER> but again this fails?
Regards
ispy
Pc SPEC:
Current OS WinXPSP3 working within CMD.EXE & I have also tried to use Command.com from CMD window. PC is Small-Form Factor Intel core i7 vPro with 8 gig ram usb non-wireless mouse setup on dual boot "grub for dos" non-bootsector dual boot mechanism with Q4OS Linux OS. I have portable Vbox installed off usb drive with Win98SE & ME
- I have tried googling for a similar problem without much luck
- I have not yet tried within W98SE Vbox but first it needs to work within XP first (possibly Win3.1?)
- I have tried to examine the script with echo on instead of echo off
- I have tried to break the script down into stages & stopped the script from deleting the temp files it makes to see what is within these temp bat files.
- Have tried to echo the variable upon completion to see if it is defined & the answer is no
Can someone shed some light on what I am doing wrong with a small elementary batch script that I am trying to compile. I'm sure it is something simple that I am missing & will KICK myself when I discover what but the problem has got me confounded.
The batch script (IF possible needs to work in XP as well as Win98SE [& a luxury would be Win3.1]) Here is the batch script with comments to try to explain what I am trying to do with the script?
@ECHO ON (Used to see whats going on with the batch script will @echo off when fixed)
SET DRV= (Used to clear any previous Drive: Vars so starting from fresh each time)
ECO.COM SET DRV=>T1.BAT (ECO.COM is a debug echo script that permits not having CRLF)
ECHO PROMPT $N:>T2.BAT ($N: is a Prompt for Drive: not $p$g standard prompt redirected to T2 temp bat
COPY T1.BAT+T2.BAT T3.BAT>NUL (Joins 2No temp bats to form third temp bat with copy)
CALL T3.BAT (Calls T3 temp bat with one line of SET code)
:: DEL T?.BAT (Deletes all three temp bats to cleanup)
ECHO Your Current Drive is %DRV% Tests if the variable is defined the answer is no)
pause (Pause is used to retain info on the screen when script completes)
T1.BAT has the following text therein SET DRV=
T2.BAT has the following text therein PROMPT $N:
T3.BAT lastly has this text before being called SET DRV=PROMPT $N:
Is the newline carriage return square box thingy on next line
Within the CMD window I get the following text:
Your Current Drive is <Nothing>
Press any key to continue . . . <cursor>
What this script is supposed to do is get the Drive: prompt into a variable e.g. "C:" (without quotes) but it ain't happening at my end? Some help would be appreciated, thanks in advance
P.S. Oh by the way & as feedback in respect of "How to get help for a batch script - quickly!" the links within the post do not work for me I am using Palemoon which is firefox browser on XP. Could someone check to see if its just me with my browser or are the links not going anywhere?
P.S2 - I have tried to establish this script from the command prompt. If for instance I type at the command prompt "PROMPT $N:" & hit the <ENTER> key this works manually typing it in manually however within batch it is failing, any ideas Please? I have also tried Echoing prompt & using a key-stuffer to simulate the <ENTER> but again this fails?
Regards
ispy
-
- Posts: 240
- Joined: 04 Mar 2014 11:14
- Location: germany
Re: Problem with variable Drive setup for XP/W98SE
Hi,
I think its so (untestet)
Phil
I think its so (untestet)
Code: Select all
echo exit |command /k prompt set drive=$N |find "set" >Tempdrv.bat
echo.>>Tempdrv.bat
Call Tempdrv
Echo %drive%
Re: Problem with variable Drive setup for XP/W98SE
Someone correct me if I'm wrong, but you can useto get the drive letter the batch is currently being run from. I can't recall if this worked this way in 95/98/ME, but I don't think it worked this way in DOS 6.0 and earlier.
So in your batch this linewould change toTry it and let me know what happens. I am only an amateur compared to the pros here, but I've been working with DOS since the DOS days cutting my teeth on DOS 3.3 so hopefully I remember this right!
Code: Select all
%~d0
So in your batch this line
Code: Select all
ECHO PROMPT $N:>T2.BAT ($N: is a Prompt for Drive: not $p$g standard prompt redirected to T2 temp bat
Code: Select all
ECHO %~d0>T2.BAT
Re: Problem with variable Drive setup for XP/W98SE
The command extension "%~d0"-syntax exclusively works for "cmd.exe" and doesn't work under "command.com", so it won't work under Win9x.Samir wrote:I can't recall if this worked this way in 95/98/ME
Re: Problem with variable Drive setup for XP/W98SE
Thank you for the correction penpen! There were certainly more limits back in the day, that's for sure.
Re: Problem with variable Drive setup for XP/W98SE
I remembered another way to get the current drive and path--and it was simple and I used to use it so much back in the dayWithout any options it will simply display the present working drive with full path.
Code: Select all
CD
Re: Problem with variable Drive setup for XP/W98SE
Maybe this could help:
https://www.robvanderwoude.com/batchfiles.php
https://www.robvanderwoude.com/batexamples.php
https://www.robvanderwoude.com/files/bootdriv_dos.txt
https://www.robvanderwoude.com/amb_cdrom.php
https://www.robvanderwoude.com/bootdrive.php
https://www.robvanderwoude.com/sourceco ... rdrive_dos
10 or 15 years ago there was a site maintained by Frank Peter Schultze (fpschultze.de ?) . Looks like this might be a copy: fpschultze.blogspot.com (didn't check it).
Saso
https://www.robvanderwoude.com/batchfiles.php
https://www.robvanderwoude.com/batexamples.php
https://www.robvanderwoude.com/files/bootdriv_dos.txt
Code: Select all
@ECHO OFF
:: BOOTDRV.BAT
:: Places the boot drive letter in environment variable BOOTDRV
::
:: Written by Rob van der Woude
:: http://www.xs4all.nl/~robw/rob/
::
:: Limitation: Uses COMSPEC to determine boot drive, so if a different
:: command processor was specified by either the SHELL
:: command or by a SET COMSPEC=... command, this batch file
:: will be fooled and display the wrong drive.
::
SET BOOTDRV=
ECHO %COMSPEC% | CHOICE /C:ABCDEFGHIJKLMNOPQRSTUVWXYZ > NUL
IF ERRORLEVEL 1 SET BOOTDRV=A
IF ERRORLEVEL 2 SET BOOTDRV=B
IF ERRORLEVEL 3 SET BOOTDRV=C
IF ERRORLEVEL 4 SET BOOTDRV=D
IF ERRORLEVEL 5 SET BOOTDRV=E
IF ERRORLEVEL 6 SET BOOTDRV=F
IF ERRORLEVEL 7 SET BOOTDRV=G
IF ERRORLEVEL 8 SET BOOTDRV=H
IF ERRORLEVEL 9 SET BOOTDRV=I
IF ERRORLEVEL 10 SET BOOTDRV=J
IF ERRORLEVEL 11 SET BOOTDRV=K
IF ERRORLEVEL 12 SET BOOTDRV=L
IF ERRORLEVEL 13 SET BOOTDRV=M
IF ERRORLEVEL 14 SET BOOTDRV=N
IF ERRORLEVEL 15 SET BOOTDRV=O
IF ERRORLEVEL 16 SET BOOTDRV=P
IF ERRORLEVEL 17 SET BOOTDRV=Q
IF ERRORLEVEL 18 SET BOOTDRV=R
IF ERRORLEVEL 19 SET BOOTDRV=S
IF ERRORLEVEL 20 SET BOOTDRV=T
IF ERRORLEVEL 21 SET BOOTDRV=U
IF ERRORLEVEL 22 SET BOOTDRV=V
IF ERRORLEVEL 23 SET BOOTDRV=W
IF ERRORLEVEL 24 SET BOOTDRV=X
IF ERRORLEVEL 25 SET BOOTDRV=Y
IF ERRORLEVEL 26 SET BOOTDRV=Z
IF "%BOOTDRV%"=="" ECHO Error checking boot drive
IF NOT "%BOOTDRV%"=="" ECHO Boot drive is %BOOTDRV%:
https://www.robvanderwoude.com/amb_cdrom.php
https://www.robvanderwoude.com/bootdrive.php
https://www.robvanderwoude.com/sourceco ... rdrive_dos
10 or 15 years ago there was a site maintained by Frank Peter Schultze (fpschultze.de ?) . Looks like this might be a copy: fpschultze.blogspot.com (didn't check it).
Saso
Re: Problem with variable Drive setup for XP/W98SE
Hello all just Posting feedback on the replies to my initial post many thanks for taking the time and trouble to post your replies, it is appreciated!,
@pieh-ejdsch(Phil) - Tried your script albeit within Vbox/Win98SE & the script did not work, all that was returned was a flashing cursor at the command prompt no temp were generated Tempdrv.bat file etc.
@Samir %~d0 does not work in Win9X as Penpen has stated (Shame it doesn't though CMD.exe only) Also in respect of CD command that is good for Drive+Path but would need further steps to process the resultant redirected text file so as to only include the Drive letter.
@miskox - Tried your script within Win9x & can confirm it works (there is the dependency of Choice & quite a lot of code to get the desired result) It will not work in XP probably due to %COMSPEC% & choice but is the best working answer so far.
I think this is a prime example of what you hope for and what you get are 2 different things in a practical sense. I have been under the mistaken impression that whatever you type at the command line could be translated into a batch-file. Typing PROMPT $N: at the command prompt then hitting the <enter> key permits getting the Drive Letter: but simulating the <enter> depress key (with a key-stuffer for e.g) & then > redirecting the Stdout into a appended text file is a bridge too far. Its a shame there is not a small debug/ASM script that would undertake this feature but would be a further dependency again.
Best regards
Ispy
@pieh-ejdsch(Phil) - Tried your script albeit within Vbox/Win98SE & the script did not work, all that was returned was a flashing cursor at the command prompt no temp were generated Tempdrv.bat file etc.
@Samir %~d0 does not work in Win9X as Penpen has stated (Shame it doesn't though CMD.exe only) Also in respect of CD command that is good for Drive+Path but would need further steps to process the resultant redirected text file so as to only include the Drive letter.
@miskox - Tried your script within Win9x & can confirm it works (there is the dependency of Choice & quite a lot of code to get the desired result) It will not work in XP probably due to %COMSPEC% & choice but is the best working answer so far.
I think this is a prime example of what you hope for and what you get are 2 different things in a practical sense. I have been under the mistaken impression that whatever you type at the command line could be translated into a batch-file. Typing PROMPT $N: at the command prompt then hitting the <enter> key permits getting the Drive Letter: but simulating the <enter> depress key (with a key-stuffer for e.g) & then > redirecting the Stdout into a appended text file is a bridge too far. Its a shame there is not a small debug/ASM script that would undertake this feature but would be a further dependency again.
Best regards
Ispy
Re: Problem with variable Drive setup for XP/W98SE
Choice.exe is not present in Windows XP. So there must be another solution to solve this issue. I might try it but currently I don't have access to XP computer. Did you check other links? I think there should be a solution already posted that would do the job.
Saso
Saso
Re: Problem with variable Drive setup for XP/W98SE
I thought that should work pretty well, so i tested that script:
On Win98SE (no matter if you are using Vbox or native) it should work pretty well, except that it should set the environment variable "drive" to "<correct drivename> exit".
There are two minor bugs in the script from Phil (a missing $_ to put exit into the next line and instead of using "command" using %comspec% to enable that script to work on all windows versions):
Code: Select all
echo exit | %ComSpec% /k prompt set drive=$N$_ |find "set" >Tempdrv.bat
echo.>>Tempdrv.bat
Call Tempdrv
Echo %drive%
penpen
Re: Problem with variable Drive setup for XP/W98SE
You could try this one, it works on win98 (tested) and should work on XP, too
Code: Select all
@echo off
if "%1" == "" goto :main
goto %1
:main
set drv=unknown
%COMSPEC% /c %0 :getdrv > drvtmp.bat
call drvtmp.bat
echo my drive is: %drv%
goto :eof
:getdrv
prompt set drv=$N
echo on
%=must be empty=%
@echo off
:eof
Re: Problem with variable Drive setup for XP/W98SE
Hi Folks ,
I think I may have a solution to this problem I have adapted a script which I have found on PC-Mag article which I think was in the main for 9X but it seems to work reasonably well in XP as well even though it uses command.com rather than native CMD (& one other caveat it reports back in SFN format also). Maybe some experts could perfect the script even further to iron out the wrinkles as I am not really competent enough in batch/CMD to undertake this but here is the basic skeleton. What the batch file does is sets both your current drive and your current path to variables here it is in raw format: It works in XP as well as Windows98SE Dos/CMD.
From the batch file you could comment out the DEL GD$?.BAT like this :: DEL GD$?.BAT if you want to see what is inside the temp bat files GD$1 & GD$2.BAT files for a better understanding of the mechanics of the resultant script
For me GD$1.bat temporary bat contains the following text yours will be different depending on your paths etc
And GD$2.BAT temporary bat contains the following text:
As you can see SFN's are the order of the day. I tried using %COMSPEC% instead of command.com but it crashed in XP. I have only put the pause command to view the contents of the variables by holding the Dos Prompt & CMD window open.
Many Thanks Penpen & Jeb for your batch script contributions, I will try your scripts tomorrow and get back to you with any observations that may arise within 9X & XP, to me the more variations the better particularly from the perspective of others who may visit the site looking for a similar solution. To me it is useful to setup your drive and current path as variables, very useful but for me not so easy to setup though.
Edit P.S. - Following a comment by Samir @ Post #6, One other thing I was experimenting with was the CD command as that will on it's own with a redirect give you your path something like CD>T1.BAT So I experimented with CD\ CDBackslash with a redirect like CD\>T1.BAT as CD Backslash gives you your root Drive but the introduction of the back slash causes the script to fail for some reason. However I can report that CD\ works in both Win XP & Windows98SE manually typed in. It seems to fail in batch script with a reported error in respect of the backslash possibly some other batch code is required?
Best Regards,
Ispy
I think I may have a solution to this problem I have adapted a script which I have found on PC-Mag article which I think was in the main for 9X but it seems to work reasonably well in XP as well even though it uses command.com rather than native CMD (& one other caveat it reports back in SFN format also). Maybe some experts could perfect the script even further to iron out the wrinkles as I am not really competent enough in batch/CMD to undertake this but here is the basic skeleton. What the batch file does is sets both your current drive and your current path to variables here it is in raw format: It works in XP as well as Windows98SE Dos/CMD.
Code: Select all
@ECHO OFF
IF NOT "%2"=="" GOTO :TWOTime
ECHO @PROMPT %0 $n: $p > GD$1.BAT
COMMAND /E:2048 /C GD$1.BAT > GD$2.BAT
GD$2.BAT
:TWOTime
DEL GD$?.BAT
SET Drv=%1
SET CDir=%2
ECHO YOUR DRIVE IS %Drv%
ECHO YOUR CURRENT PATH IS %CDir%
pause
For me GD$1.bat temporary bat contains the following text yours will be different depending on your paths etc
Code: Select all
@PROMPT "C:\Documents and Settings\ADMIN\Desktop\RECENT\DCD.BAT" $n: $p
Code: Select all
"C:\Documents and Settings\ADMIN\Desktop\RECENT\DCD.BAT" C: C:\DOCUME~1\ADMIN\DESKTOP\RECENT
Many Thanks Penpen & Jeb for your batch script contributions, I will try your scripts tomorrow and get back to you with any observations that may arise within 9X & XP, to me the more variations the better particularly from the perspective of others who may visit the site looking for a similar solution. To me it is useful to setup your drive and current path as variables, very useful but for me not so easy to setup though.
Edit P.S. - Following a comment by Samir @ Post #6, One other thing I was experimenting with was the CD command as that will on it's own with a redirect give you your path something like CD>T1.BAT So I experimented with CD\ CDBackslash with a redirect like CD\>T1.BAT as CD Backslash gives you your root Drive but the introduction of the back slash causes the script to fail for some reason. However I can report that CD\ works in both Win XP & Windows98SE manually typed in. It seems to fail in batch script with a reported error in respect of the backslash possibly some other batch code is required?
Best Regards,
Ispy
Re: Problem with variable Drive setup for XP/W98SE
@ispy:
did you try (in 9X, Xp...) this:
instead of
(can't test this right now)
Saso
did you try (in 9X, Xp...) this:
Code: Select all
echo %cd% >temp.file
Code: Select all
cd>temp.file
Saso
Re: Problem with variable Drive setup for XP/W98SE
Hi miskox,
tested, it works in XP, but not in w98.
That was expected, because XP has nearly the same features and bugs like W10.
It could be a good solution to write different code for XP and W98 and detect which part has to be used.
Something like
Code: Select all
echo %cd%
That was expected, because XP has nearly the same features and bugs like W10.
It could be a good solution to write different code for XP and W98 and detect which part has to be used.
Something like
Code: Select all
@echo off
>NUL echo dummy & goto :XP
REM Code for W95
...
:XP
Re: Problem with variable Drive setup for XP/W98SE
Just reporting back with feedback
@ Saso As Jeb has stated %CD% is affiliated to Win-XP as is "cd /d" also (without quotes & just for info) these nuances are a little bit confusing, when attempting to write batch files for NT & Dos.
Anyway - @ Penpen tried your script in XP it very briefly opened the command prompt then disappeared even with a pause command within it as you mentioned. Then as you stated, tried it with %temp%\ as well same result. Tried enclosing in "" quotes same result.
Then I went to 98SE and it worked with the double quotes and the %temp%\ addition with and without quotes. It reported back: Your drive is C: press any key to continue... So I then removed the %temp%\ & quotes it still works in 98SE. If you are wondering about the colon after "C" I added it just as a test within "prompt set drive=$N:$_" line. You could also add the colon after the echo Your Drive is %drive%: line but the variable would read "C" only so its a visual not actual effect.
@ Jeb - First tried within Win XP & it kinda works, the reported message was My drive is: unknown press any key to continue... However when I used within Win98SE it worked reporting Your drive is C: press any key to continue... I also looked within the Tempdrv.bat file set drive=C: It seems it is experiencing trouble setting the variable within XP CMD for some reason but works well in 98SE?
If anyone knows of a workaround for CD redirect to bat file and CD\ redirect to bat file these could be used to glean root drive and current path but again could result in writing many lines of code to work around the back slash error that XP reports? (CD & CD\ work both in XP & 98SE)
Best Regards
Ispy
@ Saso As Jeb has stated %CD% is affiliated to Win-XP as is "cd /d" also (without quotes & just for info) these nuances are a little bit confusing, when attempting to write batch files for NT & Dos.
Anyway - @ Penpen tried your script in XP it very briefly opened the command prompt then disappeared even with a pause command within it as you mentioned. Then as you stated, tried it with %temp%\ as well same result. Tried enclosing in "" quotes same result.
Then I went to 98SE and it worked with the double quotes and the %temp%\ addition with and without quotes. It reported back: Your drive is C: press any key to continue... So I then removed the %temp%\ & quotes it still works in 98SE. If you are wondering about the colon after "C" I added it just as a test within "prompt set drive=$N:$_" line. You could also add the colon after the echo Your Drive is %drive%: line but the variable would read "C" only so its a visual not actual effect.
@ Jeb - First tried within Win XP & it kinda works, the reported message was My drive is: unknown press any key to continue... However when I used within Win98SE it worked reporting Your drive is C: press any key to continue... I also looked within the Tempdrv.bat file set drive=C: It seems it is experiencing trouble setting the variable within XP CMD for some reason but works well in 98SE?
If anyone knows of a workaround for CD redirect to bat file and CD\ redirect to bat file these could be used to glean root drive and current path but again could result in writing many lines of code to work around the back slash error that XP reports? (CD & CD\ work both in XP & 98SE)
Best Regards
Ispy