Command$ gives wrong data

General FreeBASIC programming questions.
Post Reply
Jawade
Posts: 228
Joined: Apr 25, 2008 19:13

Command$ gives wrong data

Post by Jawade »

If I read the Command$, he expands the '*'.

Code: Select all

Extern _CRT_glob Alias "_CRT_glob" As Integer
Dim Shared _CRT_glob As Integer = 0

Print Command$
If I start the file 'test.exe' and give an wildcard, he expands it, despite
the first lines.

C:\Users\Beheerder\Sources\test>test test*
test.bas test.exe

What I want is 'test*'
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Command$ gives wrong data

Post by grindstone »

"A computer does not what you want it to do but what you tell it to do" ;-)

You have to put the parameter in quotes:

C:\Users\Beheerder\Sources\test>test "test*"
test*
Jawade
Posts: 228
Joined: Apr 25, 2008 19:13

Re: Command$ gives wrong data

Post by Jawade »

Thank you, but it don't work. It works with single quotes, and also with 'test* or -test*
But that is not the intention. I see it as a miss, sorry. I think I use -test*
counting_pine
Site Admin
Posts: 6323
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: Command$ gives wrong data

Post by counting_pine »

This is to do with file globbing - it's enabled by default on all platforms. There is more info at KeyPgCommand.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Command$ gives wrong data

Post by grindstone »

Very strange: Here the disabling of the file globbing works with

Code: Select all

'' For MinGW-w64 runtime:
Extern _dowildcard Alias "_dowildcard" As Long
Dim Shared _dowildcard As Long = 0
although my system is 32bit.
Jawade
Posts: 228
Joined: Apr 25, 2008 19:13

Re: Command$ gives wrong data

Post by Jawade »

It won't work:

test.bas(13) error 4: Duplicated definition in 'Declare Function Command ( ByVal
index As Long = -1 ) As String

And the example with parameter test* gives:

test.bas

I think to do my way with -test* A weakness bid, but it works.
Jawade
Posts: 228
Joined: Apr 25, 2008 19:13

Re: Command$ gives wrong data

Post by Jawade »

grindstone, it do not work, it gives also test.bas test.exe

I think it is a big miss. It looks like FreeBASIC is a kind of bloatware.
fxm
Moderator
Posts: 12131
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: Command$ gives wrong data

Post by fxm »

On my PC under Win7 64-bit, with the following code:

Code: Select all

Extern _dowildcard Alias "_dowildcard" As Long
Dim Shared _dowildcard As Long = 0

Print Command(1)
With input parameters:
test* test.bas test.exe
Program output:
test*
[edit]
With the code line:

Code: Select all

Print Command
I obtain:
test* test.bas test.exe
Last edited by fxm on Oct 09, 2017 13:25, edited 1 time in total.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Command$ gives wrong data

Post by grindstone »

Seems like _dowildcard works at both 32 and 64bit.

@Jawade: From my experience such persistent bugs are mostly caused by some trifle in the source code (at a place where you won't expect it). Please check your code before railing against freeBasic.
Jawade
Posts: 228
Joined: Apr 25, 2008 19:13

Re: Command$ gives wrong data

Post by Jawade »

fxm: Now it works, because I start de testfile after compiling. In a .bat compiled it didnt work well. Thank you.
Jawade
Posts: 228
Joined: Apr 25, 2008 19:13

Re: Command$ gives wrong data

Post by Jawade »

Sorry for that, but it's very frustrating if it won't work. I compiled it in a .bat and than it goes wrong. But nou I have the solution. Thanks to all.
grindstone
Posts: 862
Joined: May 05, 2015 5:35
Location: Germany

Re: Command$ gives wrong data

Post by grindstone »

it's very frustrating if it won't work.
I know, I know... <grin>
xlucas
Posts: 334
Joined: May 09, 2014 21:19
Location: Argentina

Re: Command$ gives wrong data

Post by xlucas »

Interesting! I had always assumed that FreeBasic did not do this; that it happened in GNU/Linux only and because the system shell does it. I expected it to not work the same when run in DOS or Windows, but after reading this post and the wiki about Command, I think I understand why it is done. It looks like, because GNU/Linux does it and FreeBasic can't "undo it" in that platform, it has been implemented for the other platforms so that programs work the same way on all of them by default. This behaviour is different from that of QuickBasic, but what can one do? On the other hand, QuickBasic used to pass everything to uppercase and remove the leading space character (if present) from the command line before passing it to Command$. I remember I used to read the command line from the PSP instead when I needed to be able to see the upper/lower case.

It's not easy to face the job of making a programming language transparently cross-platform, I realise.
jj2007
Posts: 2326
Joined: Oct 23, 2016 15:28
Location: Roma, Italia
Contact:

Re: Command$ gives wrong data

Post by jj2007 »

Jawade wrote:I think it is a big miss. It looks like FreeBASIC is a kind of bloatware.
This comment tells me more about you than about FreeBasic.

The behaviour is certainly a bit odd, greetings from Linux, but if somefile* gets passed as a commandline, then it was definitely not a user who dragged a file over the executable. So it was another application. Instruct that application to use "#" instead of "*", and the problem is solved.
St_W
Posts: 1626
Joined: Feb 11, 2009 14:24
Location: Austria
Contact:

Re: Command$ gives wrong data

Post by St_W »

grindstone wrote:Seems like _dowildcard works at both 32 and 64bit.
Yes, because both the 32-bit and 64-bit FreeBasic builds for Windows are done with the MinGW-w64 toolchain now by default (since FB 1.0.0 IIRC). See also (e.g. for 1.05): https://freebasic.net/forum/viewtopic.php?f=1&t=24363 It lists the used toolchains and there's also a package built with the old mingw.org toolchain.
Post Reply