Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DAY 033: COMMAND$
#2
Quote:COMMAND$(0): This is a special parameter of COMMAND$() that retrieves the current drive, path, and name of the running app. Pretty cool, right?

The correct answer here is: [4] Pete is wrong!  Tongue

Command$(0) does NOT retrieve the current drive, path, and name of the running app.  He's right though, it'd be pretty cool if that's what it did for you -- but it's not.

What Command$(0) does do is return the command which the user used to start your program.  Let me explain, so it's not confusing to anyone.

Let's say you open up File Explorer and navigate to "C:\QB64PE\" and from there you click on "qb64pe.exe" to start up our IDE like usual.  At that point, file explorer would use "C:\QB64PE\qb64pe.exe" to start the program which you clicked on.  COMMAND$(0) would have in it, "C:\QB64PE\qb64pe.exe" -- which is where Pete is basing his misinformation off from.

Now, here's a different scenario:   

Let's say you open a command prompt.  You type in "CD C:\QB64PE".  You then type in "qb64pe" to run the executable inside the folder that you just navigated to.  COMMAND$(0), in this case, is simply going to be "qb64pe".

COMMAND$(0) simply returns to you the base command of how the user started your program.  In most cases, it'll be as Pete suggests, as most people tend to start programs via the File Explorer -- BUT THAT'S NOT GUARANTEED!!

All you can depend on with COMMAND$(0) is getting back whatever command the user entered to start your program.  Drive, path, and other such information is not guaranteed.

If you want the drive and path, use _CWD$ at the start of your program and store it in a variable if necessary, before something changes its value.  _CWD$ always *starts* in the directory where your EXE is located, but there's no guarantee that it'll remain there.

Code: (Select All)
MyAppDir$ = _CWD$
CHDIR "C:\"
PRINT MyAppDir$, _CWD$

With the above, you can easily see what I'm talking about with the _CWD$.

With COMMAND$(0), you should always be able to get back the name of your EXE (in case the user renamed your program), but if you want the drive and path, use _CWD$ at the start of the program to get it.  You can't be for certain that COMMAND$(0) will have that information for you at all.
Reply


Messages In This Thread
DAY 033: COMMAND$ - by Pete - 12-13-2022, 06:48 PM
RE: DAY 033: COMMAND$ - by SMcNeill - 12-13-2022, 07:14 PM
RE: DAY 033: COMMAND$ - by Pete - 12-13-2022, 07:53 PM
RE: DAY 033: COMMAND$ - by SMcNeill - 12-13-2022, 09:12 PM
RE: DAY 033: COMMAND$ - by mnrvovrfc - 12-13-2022, 07:58 PM
RE: DAY 033: COMMAND$ - by SMcNeill - 12-13-2022, 09:26 PM
RE: DAY 033: COMMAND$ - by Dav - 12-14-2022, 01:21 AM
RE: DAY 033: COMMAND$ - by vince - 12-14-2022, 01:31 AM
RE: DAY 033: COMMAND$ - by SMcNeill - 12-14-2022, 01:43 AM
RE: DAY 033: COMMAND$ - by mnrvovrfc - 12-14-2022, 08:27 AM



Users browsing this thread: 1 Guest(s)