Redirect > FAILS in Win2000

D

Dennis Leclerc

I used to be able to redirect batchfile commandline output
into a filename.ext on-the-fly under Win95 & Win98.
This method no longer works correctly/the same under
Win2000 Command.com . This example below receives the %1
input from a PIF shortcut prompt, thus MUST run under the
Win2000 Command.com (NOT CMD.exe - doesn't prompt for
input). Executed under Win2000 Command.com it returns
a "File Creation Error" and FAILS. WHY can't it handle
the LongFilename ??? Also, %0 FAILS to return the
complete filename w/extension, thus the " TYPE %0 " line
fails too. What other method??? I have a practical use
for these commands in some elaborate batchfile
routines. Thanks for help.
========================================================
@echo off
IF "%1"=="" GoTo EXIT
echo SET VAR_1=%1> .\LongFilename.VAR1.txt
TYPE %0 >> .\LongFilename.VAR1.txt
TYPE .\LongFilename.VAR1.txt
:EXIT
 
S

Scot Wiedenfeld

I'm not exactly sure I understand the issue but... here's my stab at it.

1. Cuddle your long filenames with "" e.g.:

echo blablabla > "thisfilenameiswaytolongforme.txt"

2. If you want to return the filename with extension use echo instead of
type, e.g.:

echo %0 >>"thisfilenameiswaytolongforme.txt"

How does this look?

@echo off
IF "%1"=="" GoTo EXIT
echo SET VAR_1=%1 >"LongFilename.VAR1.txt"
echo %0 >> "LongFilename.VAR1.txt"
TYPE "LongFilename.VAR1.txt"
:EXIT

Just my 2.0134 cents worth (tax included)
Scot Wiedenfeld
 
M

mole

Scot Wiedenfeld said:
I'm not exactly sure I understand the issue but... here's my stab at it.

1. Cuddle your long filenames with "" e.g.:

echo blablabla > "thisfilenameiswaytolongforme.txt"

2. If you want to return the filename with extension use echo instead of
type, e.g.:

echo %0 >>"thisfilenameiswaytolongforme.txt"

How does this look?

@echo off
IF "%1"=="" GoTo EXIT
echo SET VAR_1=%1 >"LongFilename.VAR1.txt"
echo %0 >> "LongFilename.VAR1.txt"
TYPE "LongFilename.VAR1.txt"
:EXIT

Just my 2.0134 cents worth (tax included)
Scot Wiedenfeld

I think the OP may be having problems because of the use of a *.pif to
initiate the batch with Win2K. My experience has shown that unless this
*.pif is a copy (possibly modified if the user wishes) derived from the pif
located in Win2K at %windir%\_default.pif, the batch will encounter some
error, among them generating an output file as desired, will resuilt in at
best a truncated and improperly named file. Instead try launching the batch
from a *.lnk file. If you do employ the *.lnk as the initiator for the batch
and you support a mixed fleet of Win9x/Win(NT/2K/XP) and the users have
write/modify permissions in the directory or share the *.lnk's are located
in, you must applied read-only file attributes to the *.lnk's or any Win9x
users with write/modify permissions to said *.lnk files will convert them to
*.pif's and thus for subsequent Win2K users, the shortcut will revert to the
original undesireable behavior. Placing read-only attributes blocks the
conversion of *.lnk to *.pif by Win9x users with write/modify permissions.
Generally this is only a problem for admins testing the shortcuts on a Win9x
platform. A *.lnk file will accept a command line parameter exactly as a
*.pif.

mole
 
D

Dennis

Upon further batchfile experimentation -

I find that the Win2000 Command.com simply cannot
handle/process the LongFilename.tag.ext , regardless
of "quoting", etc. - so I'll have to modify my filenames
to short 8.3 convention. With that, the output redirect >
to file creation on-the-fly will work correctly.

However, the reserved " %0 " returns only the "Filename"
under Win2000 Command.com, without extension or path.
This differs significantly from the previous Win98/95
behavior, and from Win2000 CMD.exe,
where the reserved " %0 " returns
the "Drive:\Full\Path\Filename.ext" .
I will have to modify the command to explicitly name the
file instead of using the 'dynamic' " %0 "

Any other ideas?
 
M

Mark Zbikowski \(MSFT\)

The COMMAND.COM that is present in NT 4,
Windows 2000, XP, and Windows 2003 Server
does not support long file names.

Use CMD.EXE.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top