Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Batch file conversion - NT to 98

0 views
Skip to first unread message

James Jones

unread,
Mar 24, 2001, 12:06:12 PM3/24/01
to
Hi,

I have a batch file written for NT that contains commands that only appear
to work on NT, as opposed to my Win98 machine. I have looked for replacement
commands in 98, but have yet to find anything relevant.

I would be grateful if someone could either tell me how to convert the batch
file to work in 98, or point me in the right direction to do it myself.

The batch file is used to run a program in a set directory, on an input file
not necessarily in the same directory. The output is redirected the
directory the input file was in.

Heres the batch file:

@echo off
setlocal //This doesn't work in 98

rem go to the directory where the MAD input file lives ... we'll execute
rem from there

pushd %~dp1 //This doesn't work in 98

rem if invoked via "Send To", the MAD input file name is the short "8.3"
DOS
rem name ... the following command expands the short name to the full name
and
rem loads it into a local environment variable

for /f %%n in ('dir/b/x %1') do set fname=%%n
//This doesn't work in 98

rem set up a (local) environment variable with dict file location

set dict=d:\mma\mad\MAD8dl.dict

rem See if that worked
rem set
rem more < %dict%

rem run MAD8acc

d:\mma\mad\MAD8dl < %fname% > echo.txt

rem all done ...

endlocal
//This doesn't work in 98
popd
//This doesn't work in 98
@echo on

Thanks for your help,

James Jones
titch...@lineone.net

Frank-Peter Schultze

unread,
Mar 24, 2001, 2:14:08 PM3/24/01
to
"James Jones" wrote:


> setlocal //This doesn't work in 98

SETLOCAL saves a 'snapshot' of the current environment. SETLOCAL's
counterpart is ENDLOCAL below. It restores environment using the 'snapshot'.
In MS-DOS and Windows 9x there is no command pair like this.


> pushd %~dp1 //This doesn't work in 98

This works in 98:

:: Create 'whitespacecompatible' POPD.BAT in temp. dir
:: (We use POPD.BAT later)
echo @prompt $N:$_cd "$P"$_>%TEMP%.\~tmp.bat
%COMSPEC% /c %TEMP%.\~tmp.bat > %TEMP%.\POPD.BAT
del %TEMP%.\~tmp.bat
:: Change drive, if necessary (whitespacecompatible)
echo %1 | FIND ":" | if NOT errorlevel 1 %1.\
:: Change dir using fully qualified filename, ie:
cd %1\..


> for /f %%n in ('dir/b/x %1') do set fname=%%n

BTW, in NT this can be shortened to: set fname=%~sn1


> //This doesn't work in 98

This works in 98:

:: Create temp. file w/9 empty lines...
echo.>%TEMP%.\~tmp1.bax
for %%C in (2 3 4 5 6 7 8 9) do echo.>>%TEMP%.\~tmp1.bax
:: ... and append DIR's output (10th line)
dir %1 | FIND "%1" >> %TEMP%.\~tmp1.bax
:: Compare temp. file w/an empty file (NUL) and set the
:: maximum consecutive mismatches to 10 lines. The 10th
:: line contains DIR's output, "10:" will be prefixed by
:: FC. Save this line as temp. batch file
FC NUL %TEMP%.\~tmp1.bax /n /lb10|FIND " 10: ">%TEMP%.\~tmp1.bat
:: Since FC's output begins w/10, and ~tmp1.bat is FC's
:: output, ~tmp1.bat executes a "10" command.
:: create 10.bat to set fname var to filename (arg1)
:: and extension (arg2)
echo set fname=%%1.%%2>%TEMP%.\10.bat
:: Save PATH
path > %TEMP%.\~tmp2.bat
:: Set PATH to temp dir
path %TEMP%
:: Call the temp. batch files
:: ~tmp1.bat executes 10.bat which set the fname var
:: ~tmp2.bat restores the PATH
for %%B in (~tmp1 ~tmp2) do call %TEMP%.\%%B.bat
:: Cleanup
for %%F in (~tmp1 ~tmp2 10) do del %TEMP%.\%%F.ba?


> endlocal
> //This doesn't work in 98

In Windows 98 unset your variables here


> popd
> //This doesn't work in 98

:: call and del POPD.BAT in temp. dir:
for %%C in (call del) do %%C %TEMP%.\POPD.BAT


HTH


--
__ _ _
|_ |_)(__ http://www.fpschultze.de
___| | ____)chultze_________________________________________________
I am logged in, therefore I am.

Todd Vargo

unread,
Mar 25, 2001, 2:41:05 AM3/25/01
to

"Frank-Peter Schultze" <fpsch...@my-deja.com> wrote in message
news:99ireq$oc1$1...@news.nikoma.de...

> "James Jones" wrote:
>
>
> > setlocal //This doesn't work in 98
>
> SETLOCAL saves a 'snapshot' of the current environment. SETLOCAL's
> counterpart is ENDLOCAL below. It restores environment using the
'snapshot'.
> In MS-DOS and Windows 9x there is no command pair like this.

No but you could use %COMSPEC%/K and EXIT with recursion. Not as pretty as
using NT's SETLOCAL, but it gets the job done.

::example.bat
::(Note, I do not use NT.)
if %0==%1 goto continue
::SETLOCAL
%COMSPEC%/E:4096/K %0 %0 %1 %2 %3 %4 %5 %6 %7 %8 %9
goto end

:continue
shift
bla-bla-bla
::ENDLOCAL
exit

:end


--
Todd Vargo (body of message must contain my name to reply by email)

0 new messages