command$ ACTUAL CASE?

 BBS: Inland Empire Archive
Date: 04-23-92 (08:44)             Number: 137
From: BOB ROSS                     Refer#: NONE
  To: DAVID BLISS                   Recvd: NO  
Subj: command$ ACTUAL CASE?          Conf: (2) Quik_Bas
In a message of <Apr 19 00:16>, David Bliss (1:3639/ writes:
 >Is there any way to get the COMMAND$ in the case it was entered?
 >I have a kludge for 4DOS but I cant use that in anything I
 >distribute.  any help will be appreciated.

Yes.  Cut from this echo:

 BR> There was a discussion awhile back regarding how to
 BR> retrieve the arguments in the command line in the case
 BR> they were entered in.  I let this slip by without saving the solution.

  Here's some code that should work Bob, and I'm taking a
stab at preserving the current PSP.  It tends to get
trashed if steps aren't taken.  I don't think it's
important to protect it unless you have a need to grab
command$ somewhere else in your program.  Not sure about
that though..  Anyway, I just threw this together and it
seems to work:

  DIM RegsX AS RegTypeX
  DIM Regs AS RegType
  'get current PSP segment..
  Regs.AX = &H5100
  CALL interrupt(&H21, Regs, Regs)
  OldSeg% = Regs.BX
  'peek all data from PSP area..
  oldpsp$ = ""
  DEF SEG = OldSeg%
  FOR x% = 0 TO 255
  oldpsp$ = oldpsp$ + CHR$(PEEK(x%))
  NEXT x%
  'get real command line from default DTA area..
  RegsX.AX = &H2F00
  CALL interruptx(&H21, RegsX, RegsX)
  DEF SEG = RegsX.ES
  TRUECMD$ = ""
  FOR z%= 2 TO 128
  a% = PEEK(RegsX.BX + z%)
  IF a% = 13 THEN EXIT FOR
  IF a% < 127 AND a% > 27 THEN
  NEXT z%
  'write (poke) data back into psp..
  DEF SEG = OldSeg%
  FOR x% = 0 TO 255
   byte% = ASC(MID$(oldpsp$, x% + 1, 1))
   POKE x%, byte%
  NEXT x%
  'print the true command line..


In a message dated <10-23-91 (10:39)> From: BOB ROSS To: ALL --

BR>There was a discussion awhile back regarding how to retrieve the
BR>arguments in the command line in the case they were entered in.  I let
BR>this slip by without saving the solution.

BR>Could someone please provide some code on how to do this.

Here's some code I captured.  I haven't tried it so
caveat emptor ; your mileage may vary; and other weasel words.

'Date: 04-11-91
'Subj: ORIGINAL COMMAND LINE; preserving lower case
'Conf: QBASIC (62)

'The command line as entered at the DOS prompt, in all its mixed-case
'splendour, is found at offset &H81 of the program's PSP (Program Segment
'Prefix), with the length of the command string at offset &H80 of the
'Finding your PSP from within QuickBASIC entails Interrupt calls.
'                                                ~~~~~~~~~
'That same area of the PSP, however, is also the default disk transfer
'area for the program (or is it the default File Control Block? - I don't
'have my references handy) At any rate, I suspect QB always defines its
'own DTAs and FCBs, so the data won't be overwritten, but this cannot
'always be guaranteed.  It would be best, therefore, if you were to get
'this info, to get it as early in the program's execution as possible,
'especially before any file I/O.

' $INCLUDE: ''

PRINT "Here's the original command line:"
PRINT "["; CmdLine; "]"


  ' CmdLine - returns original command line
  DIM Regs AS RegType
  STATIC CmdLen, CmdBuild$, i
  ' DOS Interrupt 21h service 62h returns the segment
  ' address of the running program's PSP in the bx register.
  ' = &H6200
  CALL Interrupt(&H21, Regs, Regs)
  DEF SEG = Regs.BX
  ' The command line's length is found at offset 80h of the PSP
  ' and the actual command line starts at 81h
  CmdBuild$ = ""
  CmdLen = PEEK(&H80)
  FOR i = 1 TO CmdLen
    CmdBuild$ = CmdBuild$ + CHR$(PEEK(&H80 + i))
  ' restore BASIC data segment and return data
  CmdLine$ = CmdBuild$

'+-----------[end of code]-------------------

--- QM v1.00
 * Origin: RJ's Byteline *[HST/DS]* Calgary - (403)247-3180) (1:134/75.1)
Outer Court
Echo Basic Postings

Books at Amazon:

Back to BASIC: The History, Corruption, and Future of the Language

Hackers: Heroes of the Computer Revolution (including Tiny BASIC)

Go to: The Story of the Math Majors, Bridge Players, Engineers, Chess Wizards, Scientists and Iconoclasts who were the Hero Programmers of the Software Revolution

The Advent of the Algorithm: The Idea that Rules the World

Moths in the Machine: The Power and Perils of Programming

Mastering Visual Basic .NET