Discussion:
Invalid Switch Executing Dos "DIR /X" Command from BP7
(too old to reply)
Jim Bishop
2006-05-15 15:52:28 UTC
Permalink
I'm getting the following error:

Borland Pascal Version 7.0 Copyright (c) 1983,92 Borland International
Invalid switch - /X

when I run the following short program compiled in Real Mode with no
conditionals defined. From a command prompt the "DIR /X >TEST.TXT"
works fine. Any pointers would be appreciated. I'm trying to map long
directory/file names to short directory/file names.

As a side note, when I comment out the SetMemTop lines in FreePascal, it
runs fine; so I don't think it's the command itself.

Jim




PROGRAM test;
USES
DOS, MEMORY;
{===============================================}
PROCEDURE DO_COMMAND(S : STRING);
BEGIN
{$IFNDEF DPMI}
SetMemTop(HeapPtr);
{$ENDIF}
SwapVectors;
Exec(Getenv('comspec'), '/c ' + S);
SwapVectors;
{$IFNDEF DPMI}
SetMemTop(HeapEnd);
{$ENDIF}
END; { DO_COMMAND }
{================================================}
BEGIN {test}
do_command('DIR /X >TEMP.TXT');
END. {test}
Maurice.Lombardi
2006-05-15 17:08:49 UTC
Permalink
Post by Jim Bishop
Borland Pascal Version 7.0 Copyright (c) 1983,92 Borland International
Invalid switch - /X
when I run the following short program compiled in Real Mode with no
conditionals defined. From a command prompt the "DIR /X >TEST.TXT"
works fine. Any pointers would be appreciated. I'm trying to map long
directory/file names to short directory/file names.
What is the /X switch supposed to mean ?
What is your Windows flavor ?
For me (W98se) it fails already at command prompt.

Maurice
--
Maurice Lombardi
Laboratoire de Spectrometrie Physique,
Universite Joseph Fourier de Grenoble, BP87
38402 Saint Martin d'Heres Cedex FRANCE
Tel: 33 (0)4 76 51 47 51
Fax: 33 (0)4 76 63 54 95
mailto:***@ujf-grenoble.fr
Hanford Carr <"hwcarr"@lmcinvestments.com>
2006-05-15 17:55:05 UTC
Permalink
Post by Maurice.Lombardi
Post by Jim Bishop
Borland Pascal Version 7.0 Copyright (c) 1983,92 Borland International
Invalid switch - /X
when I run the following short program compiled in Real Mode with no
conditionals defined. From a command prompt the "DIR /X >TEST.TXT"
works fine. Any pointers would be appreciated. I'm trying to map long
directory/file names to short directory/file names.
What is the /X switch supposed to mean ?
What is your Windows flavor ?
For me (W98se) it fails already at command prompt.
Maurice
snip
/N New long list format where filenames are on the far right.
/X This displays the short names generated for non-8dot3 file
names. The format is that of /N with the short name
inserted
before the long name. If no short name is present, blanks
are
displayed in its place.

I ran dir /? in Windows 2000 and copied the /X switch info and /N since
/X mentions it.
Switch must be new in NT or 2000.

Hanford
Wolfgang Ehrhardt
2006-05-15 18:06:00 UTC
Permalink
Post by Jim Bishop
Borland Pascal Version 7.0 Copyright (c) 1983,92 Borland International
Invalid switch - /X
when I run the following short program compiled in Real Mode with no
conditionals defined. From a command prompt the "DIR /X >TEST.TXT"
works fine. Any pointers would be appreciated. I'm trying to map long
directory/file names to short directory/file names.
As a side note, when I comment out the SetMemTop lines in FreePascal, it
runs fine; so I don't think it's the command itself.
Jim
PROGRAM test;
USES
DOS, MEMORY;
{===============================================}
PROCEDURE DO_COMMAND(S : STRING);
BEGIN
{$IFNDEF DPMI}
SetMemTop(HeapPtr);
{$ENDIF}
SwapVectors;
Exec(Getenv('comspec'), '/c ' + S);
SwapVectors;
{$IFNDEF DPMI}
SetMemTop(HeapEnd);
{$ENDIF}
END; { DO_COMMAND }
{================================================}
BEGIN {test}
do_command('DIR /X >TEMP.TXT');
END. {test}
Which Operation System? I Guess Win2000 or XP, because under pure DOS
or Win98 /X is no valid option. What is the value of
Getenv('comspec')?

It maybe that command.com does not support /X but cmd.exe does, but
you cannot start cmd.exe from a 16 bit program (you CAN start it from
a 32 bit Freepascal console application). If this is the case you can
try the START command if you OS supports it.

Hope that helps
Wolfgang
--
In order to e-mail me a reply to this message, you will have
to remove PLEASE.REMOVE from the address shown in the header
or get it from http://home.netsurf.de/wolfgang.ehrhardt
(Free AES, CRC, Hash, and HMAC source for Pascal/Delphi)
Jim Bishop
2006-05-15 19:39:33 UTC
Permalink
Post by Wolfgang Ehrhardt
Post by Jim Bishop
Borland Pascal Version 7.0 Copyright (c) 1983,92 Borland International
Invalid switch - /X
when I run the following short program compiled in Real Mode with no
conditionals defined. From a command prompt the "DIR /X >TEST.TXT"
works fine. Any pointers would be appreciated. I'm trying to map long
directory/file names to short directory/file names.
As a side note, when I comment out the SetMemTop lines in FreePascal, it
runs fine; so I don't think it's the command itself.
Jim
PROGRAM test;
USES
DOS, MEMORY;
{===============================================}
PROCEDURE DO_COMMAND(S : STRING);
BEGIN
{$IFNDEF DPMI}
SetMemTop(HeapPtr);
{$ENDIF}
SwapVectors;
Exec(Getenv('comspec'), '/c ' + S);
SwapVectors;
{$IFNDEF DPMI}
SetMemTop(HeapEnd);
{$ENDIF}
END; { DO_COMMAND }
{================================================}
BEGIN {test}
do_command('DIR /X >TEMP.TXT');
END. {test}
Which Operation System? I Guess Win2000 or XP, because under pure DOS
or Win98 /X is no valid option. What is the value of
Getenv('comspec')?
It maybe that command.com does not support /X but cmd.exe does, but
you cannot start cmd.exe from a 16 bit program (you CAN start it from
a 32 bit Freepascal console application). If this is the case you can
try the START command if you OS supports it.
Hope that helps
Wolfgang
Yes thank you, Wolfgang, that sounds much closer to what I need. And
yes, my os is XP. The comspec variable was command.com and not cmd.exe
when I debugged the program.

Unfortunately do_command('START DIR /x >TEMP.TXT'); returns an empty
TEMP.TXT file. So, maybe I misunderstand your suggestion. Also I want
to process the re-directed file after this command, so I need the
shelled process to terminate and my application to continue automatically.

Jim
Wolfgang Ehrhardt
2006-05-15 21:23:24 UTC
Permalink
Post by Jim Bishop
Unfortunately do_command('START DIR /x >TEMP.TXT'); returns an empty
TEMP.TXT file. So, maybe I misunderstand your suggestion. Also I want
to process the re-directed file after this command, so I need the
shelled process to terminate and my application to continue automatically.
Finally here is a solution which works under Win200:

Replace: Exec(Getenv('COMSPEC'), '/c ' + S);
by: Exec(FSearch('CMD.EXE',GetEnv('PATH')), '/c ' + S);

Hope in works under XP

Wolfgang
--
In order to e-mail me a reply to this message, you will have
to remove PLEASE.REMOVE from the address shown in the header
or get it from http://home.netsurf.de/wolfgang.ehrhardt
(Free AES, CRC, Hash, and HMAC source for Pascal/Delphi)
Jim Bishop
2006-05-15 23:35:32 UTC
Permalink
Post by Wolfgang Ehrhardt
Post by Jim Bishop
Unfortunately do_command('START DIR /x >TEMP.TXT'); returns an empty
TEMP.TXT file. So, maybe I misunderstand your suggestion. Also I want
to process the re-directed file after this command, so I need the
shelled process to terminate and my application to continue automatically.
Replace: Exec(Getenv('COMSPEC'), '/c ' + S);
by: Exec(FSearch('CMD.EXE',GetEnv('PATH')), '/c ' + S);
Hope in works under XP
Wolfgang
Wolfgang, thank you. Your solution works perfectly on my XP system.

Jim
Wolfgang Ehrhardt
2006-05-15 21:05:24 UTC
Permalink
Here are some results for WIN2000 (German version).

0) command and cmd support /X

1) If I expand COMSPEC and enter the command on the command line:
C:\TEST>E:\WINNT\SYSTEM32\COMMAND.COM /C dir /x >temp.txt
Unzulässige Option - /x

2) C:\TEST>E:\WINNT\SYSTEM32\COMMAND.COM /C dir /?
does NOT show the /X option

3) If /X is replaced by /? in the BP7 pascal program the same output
as in 2 is writen to temp.txt

4) The proposed START command is no real help.

Sorry for the bad news

Wolfgang
--
In order to e-mail me a reply to this message, you will have
to remove PLEASE.REMOVE from the address shown in the header
or get it from http://home.netsurf.de/wolfgang.ehrhardt
(Free AES, CRC, Hash, and HMAC source for Pascal/Delphi)
Jim Leonard
2006-05-15 22:15:44 UTC
Permalink
Post by Jim Bishop
do_command('DIR /X >TEMP.TXT');
My question is, why bother? You can use BP functions to get all of the
information you need, and it will work regardless of what shell your OS
uses.
Jim Bishop
2006-05-15 23:34:54 UTC
Permalink
Post by Jim Leonard
Post by Jim Bishop
do_command('DIR /X >TEMP.TXT');
My question is, why bother? You can use BP functions to get all of the
information you need, and it will work regardless of what shell your OS
uses.
The short answer is that users create directories in another app where
data is located using "long filenames" and I want to put those long
filenames on a BP report, yet I have to access them via a Short filname
(FindFirst and FindNext). Unless there is some BP function that can
give me a true short to long filename conversion, I'm using the DIR /X
approach to build a table of both long & short filenames. Not very
elegant, but it works.

Jim
Jason Burgon
2006-05-16 10:52:35 UTC
Permalink
Post by Jim Bishop
Post by Jim Leonard
Post by Jim Bishop
do_command('DIR /X >TEMP.TXT');
My question is, why bother? You can use BP functions to get all of the
information you need, and it will work regardless of what shell your OS
uses.
The short answer is that users create directories in another app where
data is located using "long filenames" and I want to put those long
filenames on a BP report, yet I have to access them via a Short filname
(FindFirst and FindNext). Unless there is some BP function that can
give me a true short to long filename conversion, I'm using the DIR /X
approach to build a table of both long & short filenames. Not very
elegant, but it works.
My free DOS.PAS/WINDOS.PAS replacement unit - GDOS.PAS provides BP7 with LFN
capability when the underlying system provides the DOS LFN API. This is the
case for Win9x/ME and XP, or in MS-DOS when you have the DOSLFN "device
driver" installed.

GDOS.PAS is available from my website http://homepage.ntlworld.com/gvision/
DOSLFN is available from http://www.geocities.com/jadoxa/doslfn/
--
Jay

Author of Graphic Vision
http://homepage.ntlworld.com/gvision/
Dr John Stockton
2006-05-16 18:42:51 UTC
Permalink
JRS: In article <T9iag.152$***@newsfe2-gui.ntli.net>, dated Tue, 16
May 2006 10:52:35 remote, seen in news:comp.lang.pascal.borland, Jason
Post by Jason Burgon
My free DOS.PAS/WINDOS.PAS replacement unit - GDOS.PAS provides BP7 with LFN
capability when the underlying system provides the DOS LFN API. This is the
case for Win9x/ME and XP, or in MS-DOS when you have the DOSLFN "device
driver" installed.
GDOS.PAS is available from my website http://homepage.ntlworld.com/gvision/
DOSLFN is available from http://www.geocities.com/jadoxa/doslfn/
The newsgroup FAQ has a section "Can I use Long File Names in Turbo
Pascal?" : perhaps your code should also be mentioned there.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
Jason Burgon
2006-05-17 01:50:27 UTC
Permalink
Post by Dr John Stockton
May 2006 10:52:35 remote, seen in news:comp.lang.pascal.borland, Jason
Post by Jason Burgon
My free DOS.PAS/WINDOS.PAS replacement unit - GDOS.PAS provides BP7
with LFN capability when the underlying system provides the DOS LFN API.
This is
Post by Dr John Stockton
Post by Jason Burgon
the case for Win9x/ME and XP, or in MS-DOS when you have the DOSLFN
"device
Post by Dr John Stockton
Post by Jason Burgon
driver" installed.
GDOS.PAS is available from my website
http://homepage.ntlworld.com/gvision/
Post by Dr John Stockton
Post by Jason Burgon
DOSLFN is available from http://www.geocities.com/jadoxa/doslfn/
The newsgroup FAQ has a section "Can I use Long File Names in Turbo
Pascal?" : perhaps your code should also be mentioned there.
Yes it should be really, along with DOSLFN which now seems fairly bug-free.

--
Jay

Author of Graphic Vision
http://homepage.ntlworld.com/gvision/

Dr John Stockton
2006-05-15 20:10:43 UTC
Permalink
Post by Jim Bishop
Borland Pascal Version 7.0 Copyright (c) 1983,92 Borland International
Invalid switch - /X
when I run the following short program compiled in Real Mode with no
conditionals defined. From a command prompt the "DIR /X >TEST.TXT"
works fine. Any pointers would be appreciated. I'm trying to map long
directory/file names to short directory/file names.
As a side note, when I comment out the SetMemTop lines in FreePascal, it
runs fine; so I don't think it's the command itself.
It must be the command itself, or that which provides it, because
nothing else known that the /X in the string 'DIR /X >TEMP.TXT'
is in fact a switch.

Try it (at command prompt and in your program) with a "switch" that has
no known existence, such as /5 or /#, and with one that has "always"
existed, such as /W.

I suspect that the "DOS" at your command prompt (boot into a DOS-like
mode? MS-DOS prompt window?) is not actually the same as the "DOS" which
BP7 invokes. See what string GetEnv('comspec') actually returns -
it *may* be a surprise.
--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME. ©
<URL:http://www.merlyn.demon.co.uk/> TP/BP/Delphi/&c., FAQqy topics & links;
<URL:http://www.merlyn.demon.co.uk/clpb-faq.txt> RAH Prins : c.l.p.b mFAQ;
<URL:ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip> Timo Salmi's Turbo Pascal FAQ.
Loading...