473,609 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with Environment.Get CommandLineArgs () ?

Im using Environment.Get CommandLineArgs ().

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/
"Programmin g is an art form that fights back"
Nov 15 '05 #1
16 9527
Chad Z. Hower aka Kudzu wrote:
Im using Environment.Get CommandLineArgs ().

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#******** ******@TK2MSFTN GP12.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/
"Programmin g 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.Get CommandLineArgs ().

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/
"Programmin g 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.Get CommandLineArgs ().

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/
"Programmin g is an art form that fights back"

Nov 15 '05 #5
jerry <je***@nospam.c om> wrote in
news:MP******** *************** *@msnews.micros oft.com:
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/
"Programmin g is an art form that fights back"
Nov 15 '05 #6
jerry <je***@nospam.c om> wrote in
news:MP******** *************** *@msnews.micros oft.com:
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/
"Programmin g is an art form that fights back"
Nov 15 '05 #7
jerry <je***@nospam.c om> 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(ParamSt r(I));
ReadLn;
end.

Unless the ParamStr() is working around this...
Nov 15 '05 #8
jerry <je***@nospam.c om> 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(ParamSt r(I));
ReadLn;
end.

Unless the ParamStr() is working around this...
Nov 15 '05 #9
C# Learner <cs****@learner .here> wrote in
news:vh******** *************** *********@4ax.c om:
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/
"Programmin g is an art form that fights back"
Nov 15 '05 #10

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 application has spaces in any of the folder names, they get split up at every space. This happens regardless if I use a Sub Main(ByVal args() as String) or use System.Environment.GetCommandLineArgs(). For example, if I launch a file that's on my...
2
7932
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 listener but it fails to send a third packet. I don't get any error messages. The client sends the packet successfully but it never arrives to the listener. This only happens when I send the packets one straight after the other. If I place a delay of 2...
1
2292
by: Mahishapura | last post by:
How do i write GetCommandLineArgs implemention? Can any one help
0
1032
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 --------------------------------------------------------------------------------------- using namespace winforms; using namespace System::Runtime::InteropServices; extern "C" bool FreeConsole(void);
18
5361
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. After tracing, we find that it should be caused by "ASP.NET Application Restart" (proved by incremented counter for "Application Restarts" of "ASP.NET 1.1.4322" in "Performance" whenever the timeout happens). From MSDN documentation, we find...
2
1995
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 http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconusingudpservices.asp There error i get is 'Sub Main' is declared more than once in 'ConsoleApplication2': ConsoleApplication2.UDPMulticastListener.Main(), ConsoleApplication2.UDPMulticastListener.Main(args() As...
0
1303
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 problems: 1) I cannot run the client without administrator privileges. If I try I get the following message: Unhandled Exception: System.Security.SecurityException: Requested registry access is not allowed. at...
5
6032
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 ApplicationException with the explanation: "Object synchronisation method was called from an unsynchronised block of code". I'm sure this tells me exactly how to fix it... well, it would if I understood it. Can anyone suggest where I'm going wrong?...
5
1991
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: *************************************************************************************************************** { ........................... PrintTimeSpanProblem(); device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams); PrintTimeSpanProblem();
0
8067
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8527
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8398
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6993
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4015
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4076
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2529
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 we have to send another system
1
1658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1380
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.