Args Bug?

RandomCoder

Well-Known Member
Licensed User
Longtime User
It's my first time attempting to pass command line arguments to a Basic4PPC App that I'm writing and I may have this completely wrong.
I was expecting arguments to be seperated by commas but when I pass my App a filename I have found that it gets split into several arguments because it contains spaces.

Is it normal that spaces are used to seperate arguments?
The helpfile is a little sparse in this area so I may be wrong to expect that commas seperate variables and spaces should be acceptable.

Regards,
RandomCoder
 

specci48

Well-Known Member
Licensed User
Longtime User
Hello RandomCoder,

I don't see any problems here.

It doesn't matter how command line arguments are passed to the application as long as you access them cycling through the arraylist as mentioned in the help file:
B4X:
Sub App_Start
      For i = 0 To ArrayLen(args())-1
            Msgbox(args(i))
      Next
End Sub

specci48

Edit:
Sorry I did get your question wrong :-(
You can use quotation marks to prevent the arguments being split, e.g. MyApp "Argument 1" "Argument 2"
 
Last edited:

RandomCoder

Well-Known Member
Licensed User
Longtime User
My program could have been opened one of two ways to view a file.
The operator could start the application and then load a file, or another B4PPC App could have started the App and passed it the filename to open.

I was using...
B4X:
If ArrayLen( Args( ) ) > 0 Then FilePath = Args( 0 )

But my file name contains spaces and so it was recieved as three seperate args.
For the time being I'm doing this...
B4X:
If ArrayLen( Args( ) ) > 0 Then FilePath = AppPath & "\" & Args( 0 ) & " " & Args( 1 ) & " " & Args( 2 ) & Args( 3 )

As you can see, I'm having to build the filename and re-insert the spaces for it to work.

Regards,
RandomCoder
 

specci48

Well-Known Member
Licensed User
Longtime User
Sorry for my misleading answer in post #2 :sign0013:

It's a usual solution (in windows) to put double quotes around such space including parameters.
Just try to start an common windows application e.g. word or excel from the command line with a filename includig spaces. Double quotes will help here, too.


specci48
 
Top