Args Bug?

Discussion in 'Bug Reports' started by RandomCoder, Jun 10, 2009.

  1. RandomCoder

    RandomCoder Well-Known Member Licensed 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.

  2. specci48

    specci48 Well-Known Member Licensed 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:
    Sub App_Start
    For i = 0 To ArrayLen(args())-1
    End Sub

    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: Jun 10, 2009
  3. RandomCoder

    RandomCoder Well-Known Member Licensed 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...
    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...
    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.

  4. specci48

    specci48 Well-Known Member Licensed 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.

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice