473,788 Members | 2,744 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing filename as a command line parameter

I'm trying to pass a filename, obtained with using the fileName property
from the OpenFileDialog, as a application parameter in
Process.StartIn fo.Arguments and run a MFC/C++ application using the Start
method.

When I hardcode the application parameter such as "/name=c:\\myFile .txt" all
is well in the C++ application.

When I use the fileName property to build the parameter, the string becomes
@"/name=c:\myFile. txt" which makes the C++ application unhappy.

How does one get rid of the @ and get the single backslash to a double
backslash to make the C++ application happy?

I'll tried converting the string to a char[] and then rebuilding the string
but as soon as I add the "\\" to the string, the @ is added and only a
single backslash is added.

Thanks.

Jon.
Nov 16 '05 #1
5 5832
"jlea" <jo*@leapsoft.c om> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
I'm trying to pass a filename, obtained with using the fileName property
from the OpenFileDialog, as a application parameter in
Process.StartIn fo.Arguments and run a MFC/C++ application using the Start
method.

When I hardcode the application parameter such as "/name=c:\\myFile .txt"
all
is well in the C++ application.

When I use the fileName property to build the parameter, the string
becomes
@"/name=c:\myFile. txt" which makes the C++ application unhappy.

How does one get rid of the @ and get the single backslash to a double
backslash to make the C++ application happy?

I'll tried converting the string to a char[] and then rebuilding the
string
but as soon as I add the "\\" to the string, the @ is added and only a
single backslash is added.


Are you certain that the @ is actually in the string? @ is just the
debugger (and a way in C# code) to indicate that the normal escape
characters do not exist. For example, if you were to hardcode
"c:\\myFile.txt " and @"c:\myFile.txt " you would get the same string.

--
Adam Clauss
ca*****@tamu.ed u
Nov 16 '05 #2
Adam - thanks for responding. You are correct, the @ is actually leading
before the initial ", but I need to have the string contain "\\" and not "\"
since the C++ application needs to have it and I can't seem to get C# to
allow me to get the double backslashes; when I triy to concantenate
"/name=" with the fileName property it always just puts a single backslash.

Jon.
"Adam Clauss" <ca*****@nospam .tamu.edu> wrote in message
news:OQ******** ******@TK2MSFTN GP12.phx.gbl...
"jlea" <jo*@leapsoft.c om> wrote in message
news:%2******** *******@TK2MSFT NGP09.phx.gbl.. .
I'm trying to pass a filename, obtained with using the fileName property
from the OpenFileDialog, as a application parameter in
Process.StartIn fo.Arguments and run a MFC/C++ application using the Start method.

When I hardcode the application parameter such as "/name=c:\\myFile .txt"
all
is well in the C++ application.

When I use the fileName property to build the parameter, the string
becomes
@"/name=c:\myFile. txt" which makes the C++ application unhappy.

How does one get rid of the @ and get the single backslash to a double
backslash to make the C++ application happy?

I'll tried converting the string to a char[] and then rebuilding the
string
but as soon as I add the "\\" to the string, the @ is added and only a
single backslash is added.


Are you certain that the @ is actually in the string? @ is just the
debugger (and a way in C# code) to indicate that the normal escape
characters do not exist. For example, if you were to hardcode
"c:\\myFile.txt " and @"c:\myFile.txt " you would get the same string.

--
Adam Clauss
ca*****@tamu.ed u

Nov 16 '05 #3
"jlea" <jo*@leapsoft.c om> wrote in message
news:uj******** ******@TK2MSFTN GP11.phx.gbl...
Adam - thanks for responding. You are correct, the @ is actually leading
before the initial ", but I need to have the string contain "\\" and not
"\"
since the C++ application needs to have it and I can't seem to get C# to
allow me to get the double backslashes; when I triy to concantenate
"/name=" with the fileName property it always just puts a single
backslash.

Jon.


The double backslash is just a way to visually allow us developers to
specify and view an actual backslash (as opposed to some escape character).
When a string containing a real backslash ("\\" or @"\" whichever way you
want to think about it) gets passed the C++ application, it should realize
that it is actually a backslash and not an escape character. You shouldn't
need do anything there.

Can you show the actual code you are using (on both sides - in the C# app to
create the ProcessStartInf o and then in the C++ app to show how you are
determining the string is incorrect)?

--
Adam Clauss
ca*****@tamu.ed u
Nov 16 '05 #4
I think that I understand your problem.

You are getting a correct file name from the OpenFileDialog, and then
building an argument string for a C++ program. The contents of the
string are correct as your passing it: it contains "c:\myFile.txt" . The
problem is that the C++ application is reading the string as if it were
a command-line parameter, and is processing the \m as a special
character, not as a backslash followed by an "m".

If I am correct about this, you will want to use the .Replace()
function on the fileName parameter to fix the string so that the C++
argument parser is happy. Try something like this:

stirng argString = "/name=" + openDialog.File Name.Replace(@" \", @"\\");

This will replace all backslashes with double backslashes. See if this
helps.

Nov 16 '05 #5
Thanks for everyone's help. I have not tried Replace (though I may have but
I'll give it a try again) but what I ended up doing was to convert the
string to char[], loop over each character rebuilding the string and when I
found a single back slash in the char[], I added two single slashes. This
seemed to work but not very pretty. I'll try the replace suggestion.

One last question: now that I have successfully built a string of command
line paramaters that makes it to the C++ application ok and I see the
string, the C++ application only thinks there is a single command line
parameter and no more. For example, in the C# application, the command line
is:

"/file=myFile.txt /text=bold" and that string make it into the C++
application but only as a single parameter (I was hoping there would be 2).
When I copied/pasted the string into the C++
application->Properties->Debugging->Command line, I get the same thing until
I remove the quotes and then C++ sees two parameters.

So how does one build a string in C#, requiring quotes, and not have them
show up in __argv[]?

Thanks again.

Jon.

"Bruce Wood" <br*******@cana da.com> wrote in message
news:11******** **************@ z14g2000cwz.goo glegroups.com.. .
I think that I understand your problem.

You are getting a correct file name from the OpenFileDialog, and then
building an argument string for a C++ program. The contents of the
string are correct as your passing it: it contains "c:\myFile.txt" . The
problem is that the C++ application is reading the string as if it were
a command-line parameter, and is processing the \m as a special
character, not as a backslash followed by an "m".

If I am correct about this, you will want to use the .Replace()
function on the fileName parameter to fix the string so that the C++
argument parser is happy. Try something like this:

stirng argString = "/name=" + openDialog.File Name.Replace(@" \", @"\\");

This will replace all backslashes with double backslashes. See if this
helps.

Nov 16 '05 #6

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

Similar topics

2
1364
by: A.M | last post by:
Hi, Using WinForms, can i access to the command line parameters? Thanks, Ali
2
1099
by: Sandro | last post by:
Hi, How can I create an EXE which gets a comand-line parameter? Thanks, Sandro
0
1212
by: ohmp05 | last post by:
Hi all, I am new to deployment of application. If any one please help me on it , that will be great. During the installation of project, Installer will execute an utility( It will display Winform with all empty Textboxes . If user want to make changes in config file, user has to click on button to browse config file so it displays configuration file values on Form., and USer can make changes on it and save it to config file). Is there...
3
1159
by: Anil Gupte | last post by:
I am trying to send a command line parameter to a utilty I wrote. For example: c:\utilities\powerbuddy.exe 50 The 50 can be any number. How do I see it in the program? Do I have to create a Main rountine and pass it the value? If so how? And then, how do I load the main form of the applicaiton from the Main sub?
0
1100
by: oakwoodman | last post by:
I have the following in my procedure: CREATE PROCEDURE x_proc ( IN from_date timestamp , IN to_date timestamp , IN data_center char(1) , IN run_option int) My db2 command line is:
3
4829
by: Pia Stevens | last post by:
For a GUI CSharp program I could define command line parameter as well by declaring them in Main(): static void Main(string args) But how do I pass them easily to Form1 ? Or should I declare them in Program.cs and access them from Form1.cs ? Pia
0
973
by: Karsten W. | last post by:
Hello, my small program is a Tkinter-App which supports some command line options. When the app is started within the python environment, everything works fine. When the py2exe-frozen app is started, everything works until I pass command line parameters. Then the gui window is not displayed. It's python 2.3 on WinXp with py2exe 0.6.6. How can I debug this behaviour?
2
3973
by: =?Utf-8?B?UmFtb24gR2VuZQ==?= | last post by:
Hello: I am building a console application and I am having an issue with the command line arguments. A couple of my arguments are paths and they are usually enclosed in double quotes. If one of the paths ends up in "\", it causes the closing double quote to be ignored and the argument gets concatenated with all the subsequent arguments until another double quote is found or until the end of the string. Example:
5
1548
by: haimroman | last post by:
I have a set of several scripts. One, called "mach-list" lists all machines that match specified criteria (e.g., all Solaris machines). Others (e.g., "mach-run") do things on multiple machines; they call mach-list to get the list of machines. mach-list has command-line options. When you call mach-run, you can include on mach-run's command line the options for mach-list. How does mach-run know which options to pass to mach-list? I thought...
0
10373
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10177
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...
1
10118
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7519
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6750
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5403
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
5538
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3677
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2897
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.