GetCommandLineArgs() fails for long directory name?
-
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?
-
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?
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.
-
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?
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:
-
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?
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 -
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?
A single backlash in front of a quote character makes the parser treat that character as part of the string rather than a separator.
-
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:
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.
-
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 KreskowiakThanks. Finally someone can help out. :thumbsup:
-
A single backlash in front of a quote character makes the parser treat that character as part of the string rather than a separator.
Thanks. Finally someone can help out. :thumbsup:
-
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.