473,499 Members | 1,659 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Environment.GetCommandLineArgs() ?

Im using Environment.GetCommandLineArgs().

However some of the arguemtns passed in have spaces, so I enclosed them in
"".

For example:

"c:\temp\My area\"

The problem is when I access this as an element of the string array it
treating the last \" (And maybe others" as escape characters. So array
element [1] actually gets:

"c:\\temp\\My area\""

or

@"c:\temp\My area""

Am I just missing something obvious?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Nov 15 '05 #1
16 9480
Chad Z. Hower aka Kudzu wrote:
Im using Environment.GetCommandLineArgs().

However some of the arguemtns passed in have spaces, so I enclosed
them in "".

For example:

"c:\temp\My area\"

The problem is when I access this as an element of the string array it
treating the last \" (And maybe others" as escape characters. So array
element [1] actually gets:

"c:\\temp\\My area\""

or

@"c:\temp\My area""

Am I just missing something obvious?


What's wrong with @"c:\temp\my area"? You use @-quoting when you don't want
escape sequences to be processed. That's what @-quoting is for and the
example you list is a textbook example of when to use it.
--
Tom Porterfield
MS-MVP MCE
http://support.telop.org

Please post all follow-ups to the newsgroup only.
Nov 15 '05 #2
"Tom Porterfield" <tp******@mvps.org> wrote in
news:e#**************@TK2MSFTNGP12.phx.gbl:
What's wrong with @"c:\temp\my area"? You use @-quoting when you don't
want escape sequences to be processed. That's what @-quoting is for and
the example you list is a textbook example of when to use it.


So Im supposed to tell my users that because of a problem in C# that unlike
any other command line utilty they have to pass argumetns prefixed with a @?

So now we have type DOS comamnds like this:

copy @"c:\my area\*.*" @"d:\temp area\"

?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Nov 15 '05 #3

This may be a problem with the Windows command line
interpreter, not .NET. The CLI sees a '\"' as a literal quote.
So you get a path with a quote char at the end instead of
a backslash.

The solution is to not end paths with a backslash
or to discard any quotes at the end of the path
with a String.TrimEnd.

Chad Z. Hower aka Kudzu wrote...
Im using Environment.GetCommandLineArgs().

However some of the arguemtns passed in have spaces, so I enclosed them in
"".

For example:

"c:\temp\My area\"

The problem is when I access this as an element of the string array it
treating the last \" (And maybe others" as escape characters. So array
element [1] actually gets:

"c:\\temp\\My area\""

or

@"c:\temp\My area""

Am I just missing something obvious?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Nov 15 '05 #4

This may be a problem with the Windows command line
interpreter, not .NET. The CLI sees a '\"' as a literal quote.
So you get a path with a quote char at the end instead of
a backslash.

The solution is to not end paths with a backslash
or to discard any quotes at the end of the path
with a String.TrimEnd.

Chad Z. Hower aka Kudzu wrote...
Im using Environment.GetCommandLineArgs().

However some of the arguemtns passed in have spaces, so I enclosed them in
"".

For example:

"c:\temp\My area\"

The problem is when I access this as an element of the string array it
treating the last \" (And maybe others" as escape characters. So array
element [1] actually gets:

"c:\\temp\\My area\""

or

@"c:\temp\My area""

Am I just missing something obvious?


--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Nov 15 '05 #5
jerry <je***@nospam.com> wrote in
news:MP************************@msnews.microsoft.c om:
The solution is to not end paths with a backslash
or to discard any quotes at the end of the path
with a String.TrimEnd.


This is not a solution at all. Am I supposed to tell users "Dont put a
trailing /, there is a bug in Windows".

And the bigger concern is, is it just doing this at the end, or is it
possibly escaping other characters internally too? This is a fairly big bug
that I've seen lots of confirmations from other users.

I would hope MS plans to fix this.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Nov 15 '05 #6
jerry <je***@nospam.com> wrote in
news:MP************************@msnews.microsoft.c om:
The solution is to not end paths with a backslash
or to discard any quotes at the end of the path
with a String.TrimEnd.


This is not a solution at all. Am I supposed to tell users "Dont put a
trailing /, there is a bug in Windows".

And the bigger concern is, is it just doing this at the end, or is it
possibly escaping other characters internally too? This is a fairly big bug
that I've seen lots of confirmations from other users.

I would hope MS plans to fix this.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Nov 15 '05 #7
jerry <je***@nospam.com> wrote:
This may be a problem with the Windows command line
interpreter, not .NET. The CLI sees a '\"' as a literal quote.
So you get a path with a quote char at the end instead of
a backslash.

The solution is to not end paths with a backslash
or to discard any quotes at the end of the path
with a String.TrimEnd.


Hmm... I see this problem with a .NET app that takes parameters, but
not with the following Delphi equivalent:

program Project1;

{$APPTYPE CONSOLE}

uses
SysUtils;

var
I: Integer;
begin
for I := 1 to ParamCount do
WriteLn(ParamStr(I));
ReadLn;
end.

Unless the ParamStr() is working around this...
Nov 15 '05 #8
jerry <je***@nospam.com> wrote:
This may be a problem with the Windows command line
interpreter, not .NET. The CLI sees a '\"' as a literal quote.
So you get a path with a quote char at the end instead of
a backslash.

The solution is to not end paths with a backslash
or to discard any quotes at the end of the path
with a String.TrimEnd.


Hmm... I see this problem with a .NET app that takes parameters, but
not with the following Delphi equivalent:

program Project1;

{$APPTYPE CONSOLE}

uses
SysUtils;

var
I: Integer;
begin
for I := 1 to ParamCount do
WriteLn(ParamStr(I));
ReadLn;
end.

Unless the ParamStr() is working around this...
Nov 15 '05 #9
C# Learner <cs****@learner.here> wrote in
news:vh********************************@4ax.com:
Unless the ParamStr() is working around this...


Not that I know of. I've looked at the source before for this and didnt see
any work arounds unless a new one was added for Delphi 8.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Nov 15 '05 #10
C# Learner <cs****@learner.here> wrote in
news:vh********************************@4ax.com:
Unless the ParamStr() is working around this...


Not that I know of. I've looked at the source before for this and didnt see
any work arounds unless a new one was added for Delphi 8.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Nov 15 '05 #11

When calling a Windows API such as FindFirstFile from Delphi,
I had to be careful about trailing backslashes in directory
names. But this may very well be a problem with .NET.

I certainly appreciate that someone posted this problem.
I now know I will have to put in some command-line
argument checks that weren't there before.

C# Learner wrote...
jerry <je***@nospam.com> wrote:
This may be a problem with the Windows command line
interpreter, not .NET. The CLI sees a '\"' as a literal quote.
So you get a path with a quote char at the end instead of
a backslash.

The solution is to not end paths with a backslash
or to discard any quotes at the end of the path
with a String.TrimEnd.


Hmm... I see this problem with a .NET app that takes parameters, but
not with the following Delphi equivalent:

program Project1;

{$APPTYPE CONSOLE}

uses
SysUtils;

var
I: Integer;
begin
for I := 1 to ParamCount do
WriteLn(ParamStr(I));
ReadLn;
end.

Unless the ParamStr() is working around this...

Nov 15 '05 #12

When calling a Windows API such as FindFirstFile from Delphi,
I had to be careful about trailing backslashes in directory
names. But this may very well be a problem with .NET.

I certainly appreciate that someone posted this problem.
I now know I will have to put in some command-line
argument checks that weren't there before.

C# Learner wrote...
jerry <je***@nospam.com> wrote:
This may be a problem with the Windows command line
interpreter, not .NET. The CLI sees a '\"' as a literal quote.
So you get a path with a quote char at the end instead of
a backslash.

The solution is to not end paths with a backslash
or to discard any quotes at the end of the path
with a String.TrimEnd.


Hmm... I see this problem with a .NET app that takes parameters, but
not with the following Delphi equivalent:

program Project1;

{$APPTYPE CONSOLE}

uses
SysUtils;

var
I: Integer;
begin
for I := 1 to ParamCount do
WriteLn(ParamStr(I));
ReadLn;
end.

Unless the ParamStr() is working around this...

Nov 15 '05 #13

Yes, you are right. I did some tests using batch files which had no
problem with text which contained a trailing backslash-quote sequence.
Microsoft fell on its face with this one. The only other suggestion I can
offer is to parse Environment.CommandLine instead of using incorrectly
pre-parsed args. But I'm sure you already tried that.

I'm using VS2002. I can only hope it is fixed in later versions.

Chad Z. Hower aka Kudzu wrote...
jerry <je***@nospam.com> wrote in
news:MP************************@msnews.microsoft.c om:
The solution is to not end paths with a backslash
or to discard any quotes at the end of the path
with a String.TrimEnd.


This is not a solution at all. Am I supposed to tell users "Dont put a
trailing /, there is a bug in Windows".

And the bigger concern is, is it just doing this at the end, or is it
possibly escaping other characters internally too? This is a fairly big bug
that I've seen lots of confirmations from other users.

I would hope MS plans to fix this.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Nov 15 '05 #14

Yes, you are right. I did some tests using batch files which had no
problem with text which contained a trailing backslash-quote sequence.
Microsoft fell on its face with this one. The only other suggestion I can
offer is to parse Environment.CommandLine instead of using incorrectly
pre-parsed args. But I'm sure you already tried that.

I'm using VS2002. I can only hope it is fixed in later versions.

Chad Z. Hower aka Kudzu wrote...
jerry <je***@nospam.com> wrote in
news:MP************************@msnews.microsoft.c om:
The solution is to not end paths with a backslash
or to discard any quotes at the end of the path
with a String.TrimEnd.


This is not a solution at all. Am I supposed to tell users "Dont put a
trailing /, there is a bug in Windows".

And the bigger concern is, is it just doing this at the end, or is it
possibly escaping other characters internally too? This is a fairly big bug
that I've seen lots of confirmations from other users.

I would hope MS plans to fix this.
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"

Nov 15 '05 #15
jerry <je***@nospam.com> wrote in
news:MP************************@msnews.microsoft.c om:
Yes, you are right. I did some tests using batch files which had no
problem with text which contained a trailing backslash-quote sequence.
Microsoft fell on its face with this one. The only other suggestion I
Yep. :)

Would be nice to get someone from MS to acknowledge if they know of this or
not...
I'm using VS2002. I can only hope it is fixed in later versions.


Im using 2003. :)

Are you using .net 1.1. or 1.0?
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Nov 15 '05 #16
jerry <je***@nospam.com> wrote in
news:MP************************@msnews.microsoft.c om:
Yes, you are right. I did some tests using batch files which had no
problem with text which contained a trailing backslash-quote sequence.
Microsoft fell on its face with this one. The only other suggestion I
Yep. :)

Would be nice to get someone from MS to acknowledge if they know of this or
not...
I'm using VS2002. I can only hope it is fixed in later versions.


Im using 2003. :)

Are you using .net 1.1. or 1.0?
--
Chad Z. Hower (a.k.a. Kudzu) - http://www.hower.org/Kudzu/
"Programming is an art form that fights back"
Nov 15 '05 #17

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
486
by: Justin F | last post by:
I have set up file association for my application (VB.Net). I'm having problems getting the filename that was double-clicked. On my machine at work, if the filename being passed in to the...
2
7898
by: Theo | last post by:
Hi, I am using a tcpclient and a tcplistener to send and receive packets. The client sends a packet and the listener replies with another one. I can send 2 packets and get an answer from the...
1
2279
by: Mahishapura | last post by:
How do i write GetCommandLineArgs implemention? Can any one help
0
1024
by: Rajiv Das | last post by:
I am trying to create a Dual mode tool (runs in both console and GUI mode) similar to ILDASM. This is my progra...
18
5335
by: amdishigh | last post by:
We are experiencing the following problems concerning ASP.NET: our ASP.NET application, written in .NET 1.1 platform, and hosted in IIS 5.0 environment, experience frequent session timeout problem....
2
1983
by: Michael Turner | last post by:
Hi Guys I have just taken this article from msdn and it is coming up with an error any ideas why? If any one wants to see where I found it...
0
1291
by: Ben | last post by:
I modified the logmonitor sdk example so it would work over a network. It works great when the client and server are running on the same PC and have administrator privileges. So I have two...
5
6018
by: Steve Barnett | last post by:
I've tried to create a "single instance" application using a mutex and, as far as I can see, it's functioning right up until I close the application. When I try to release the mutex, I get an...
5
1972
by: Vibhesh | last post by:
I am facing problem with TimeSpan structure when DirectX is used. Following is the sample code that causes the problem: ...
0
7134
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7395
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
4609
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1429
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.