Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. GetCommandLineArgs() fails for long directory name?

GetCommandLineArgs() fails for long directory name?

Scheduled Pinned Locked Moved Visual Basic
csharptestingbeta-testingquestion
9 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    biop codeproject
    wrote on last edited by
    #1

    Dear all, I am testing out a command line program written in VB.NET. Of course the first line would check if the number of parameters is right. I use

    Dim inputArg() As String = System.Environment.GetCommandLineArgs()

    I find out the GetCommandLineArgs() fails if the input directory name is long! If I have input as:

    "C:\abc123\456780\" "C:\long long long space\" "abc=def, 123=456, 81\23 33"

    , I would get:

    inputArg(1)

    "c:\abc123\456780" c:\long"

    inputArg(2)

    "long"

    inputArg(3)

    "long"

    inputArg(4)

    "space"

    inputArg(5)

    "abc=def, 123=456, 81\23 33"

    Beside using a shorter path, any idea?

    9 L D 4 Replies Last reply
    0
    • B biop codeproject

      Dear all, I am testing out a command line program written in VB.NET. Of course the first line would check if the number of parameters is right. I use

      Dim inputArg() As String = System.Environment.GetCommandLineArgs()

      I find out the GetCommandLineArgs() fails if the input directory name is long! If I have input as:

      "C:\abc123\456780\" "C:\long long long space\" "abc=def, 123=456, 81\23 33"

      , I would get:

      inputArg(1)

      "c:\abc123\456780" c:\long"

      inputArg(2)

      "long"

      inputArg(3)

      "long"

      inputArg(4)

      "space"

      inputArg(5)

      "abc=def, 123=456, 81\23 33"

      Beside using a shorter path, any idea?

      9 Offline
      9 Offline
      9082365
      wrote on last edited by
      #2

      I'm assuming that the quotation marks are all part of the input in which case you're confusing the heck out of the parser! As I understand it, the input you need is .. C:\abc123\456780\ "C:\long long long space\\\" "abc=def, 123=456, 81\23 33" if the long directory name includes spaces else C:\abc123\456780\ C:\longlonglongnospaces\ "abc=def, 123=456, 81\23 33" See MS help ....

      Quote:

      Command line arguments are delimited by spaces. You can use double quotation marks (") to include spaces within an argument. The single quotation mark ('), however, does not provide this functionality. If a double quotation mark follows two or an even number of backslashes, each proceeding backslash pair is replaced with one backslash and the double quotation mark is removed. If a double quotation mark follows an odd number of backslashes, including just one, each preceding pair is replaced with one backslash and the remaining backslash is removed; however, in this case the double quotation mark is not removed.

      1 Reply Last reply
      0
      • B biop codeproject

        Dear all, I am testing out a command line program written in VB.NET. Of course the first line would check if the number of parameters is right. I use

        Dim inputArg() As String = System.Environment.GetCommandLineArgs()

        I find out the GetCommandLineArgs() fails if the input directory name is long! If I have input as:

        "C:\abc123\456780\" "C:\long long long space\" "abc=def, 123=456, 81\23 33"

        , I would get:

        inputArg(1)

        "c:\abc123\456780" c:\long"

        inputArg(2)

        "long"

        inputArg(3)

        "long"

        inputArg(4)

        "space"

        inputArg(5)

        "abc=def, 123=456, 81\23 33"

        Beside using a shorter path, any idea?

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        biop.codeproject wrote:

        Beside using a shorter path, any idea?

        • That's not even close to "long"
        • What does "fail" mean? If you report a "fail", please state whether it throws an exception, does not work as expected, or whether your computer simply died.
        • What's wrong with the results that you list at the end of your post? These are the args that I would expect.

        Bastard Programmer from Hell :suss:

        B 1 Reply Last reply
        0
        • B biop codeproject

          Dear all, I am testing out a command line program written in VB.NET. Of course the first line would check if the number of parameters is right. I use

          Dim inputArg() As String = System.Environment.GetCommandLineArgs()

          I find out the GetCommandLineArgs() fails if the input directory name is long! If I have input as:

          "C:\abc123\456780\" "C:\long long long space\" "abc=def, 123=456, 81\23 33"

          , I would get:

          inputArg(1)

          "c:\abc123\456780" c:\long"

          inputArg(2)

          "long"

          inputArg(3)

          "long"

          inputArg(4)

          "space"

          inputArg(5)

          "abc=def, 123=456, 81\23 33"

          Beside using a shorter path, any idea?

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          It's not the quotes that are screwing it up, it's the backslashes. You don't normally see directory paths specified with a trailing backslash. You can put any filepath you want inside double quotes, even if there are no spaces in the path.

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak

          B 1 Reply Last reply
          0
          • B biop codeproject

            Dear all, I am testing out a command line program written in VB.NET. Of course the first line would check if the number of parameters is right. I use

            Dim inputArg() As String = System.Environment.GetCommandLineArgs()

            I find out the GetCommandLineArgs() fails if the input directory name is long! If I have input as:

            "C:\abc123\456780\" "C:\long long long space\" "abc=def, 123=456, 81\23 33"

            , I would get:

            inputArg(1)

            "c:\abc123\456780" c:\long"

            inputArg(2)

            "long"

            inputArg(3)

            "long"

            inputArg(4)

            "space"

            inputArg(5)

            "abc=def, 123=456, 81\23 33"

            Beside using a shorter path, any idea?

            L Offline
            L Offline
            Lost User
            wrote on last edited by
            #5

            A single backlash in front of a quote character makes the parser treat that character as part of the string rather than a separator.

            speaking as ...

            B 1 Reply Last reply
            0
            • L Lost User

              biop.codeproject wrote:

              Beside using a shorter path, any idea?

              • That's not even close to "long"
              • What does "fail" mean? If you report a "fail", please state whether it throws an exception, does not work as expected, or whether your computer simply died.
              • What's wrong with the results that you list at the end of your post? These are the args that I would expect.

              Bastard Programmer from Hell :suss:

              B Offline
              B Offline
              biop codeproject
              wrote on last edited by
              #6

              Cool man! :cool: I love your reply. It really challenges me to be more careful next time when I post my question. I should clearly state what my input should be. I guess right now you should figure out I want to have three parameters. First one is a directory name. Second one is also a directory name. The last one is a special string.

              L 1 Reply Last reply
              0
              • D Dave Kreskowiak

                It's not the quotes that are screwing it up, it's the backslashes. You don't normally see directory paths specified with a trailing backslash. You can put any filepath you want inside double quotes, even if there are no spaces in the path.

                A guide to posting questions on CodeProject[^]
                Dave Kreskowiak

                B Offline
                B Offline
                biop codeproject
                wrote on last edited by
                #7

                Thanks. Finally someone can help out. :thumbsup:

                1 Reply Last reply
                0
                • L Lost User

                  A single backlash in front of a quote character makes the parser treat that character as part of the string rather than a separator.

                  speaking as ...

                  B Offline
                  B Offline
                  biop codeproject
                  wrote on last edited by
                  #8

                  Thanks. Finally someone can help out. :thumbsup:

                  1 Reply Last reply
                  0
                  • B biop codeproject

                    Cool man! :cool: I love your reply. It really challenges me to be more careful next time when I post my question. I should clearly state what my input should be. I guess right now you should figure out I want to have three parameters. First one is a directory name. Second one is also a directory name. The last one is a special string.

                    L Offline
                    L Offline
                    Lost User
                    wrote on last edited by
                    #9

                    You're welcome - it's too damn early to determine whether it's sarcasm or not :-D :java:

                    Bastard Programmer from Hell :suss:

                    1 Reply Last reply
                    0
                    Reply
                    • Reply as topic
                    Log in to reply
                    • Oldest to Newest
                    • Newest to Oldest
                    • Most Votes


                    • Login

                    • Don't have an account? Register

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • World
                    • Users
                    • Groups