471,616 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,616 software developers and data experts.

Command Line Input

I am current writing a console program that takes two file paths as command
line input. I get the command line input using the following code:

parameter = Split(Command())
input = parameter(0)
output = parameter(1)

Unforunately this method does not handle embedded spaces in the file paths,
for example C:\Documents and Settings\Administrator. Is there a simple way
to handle this? From my command prompt experience I know that paths like
this are usually passed in quotes, but the method above still breaks it
apart at the spaces. Does vb.net have a built method to handle this or do I
need to do some sort of character checking loop that looks for the quotes?

Nov 21 '05 #1
7 6493
Your command line parameters with spaces must be enclosed inside
quotation marks.

Nov 21 '05 #2
The way I think this is to be handled is as follows

Sub Main(Args() as String)
input = Args(0)
output = Args(1)
End Sub

Make sure you test to see how many arguments are there first otherwise
you'll throw an exception.

Chris
"David A. Osborn" <do********@hotmail.com> wrote in message
news:5F6Td.48045$4q6.18156@attbi_s01...
I am current writing a console program that takes two file paths as command
line input. I get the command line input using the following code:

parameter = Split(Command())
input = parameter(0)
output = parameter(1)

Unforunately this method does not handle embedded spaces in the file
paths, for example C:\Documents and Settings\Administrator. Is there a
simple way to handle this? From my command prompt experience I know that
paths like this are usually passed in quotes, but the method above still
breaks it apart at the spaces. Does vb.net have a built method to handle
this or do I need to do some sort of character checking loop that looks
for the quotes?

Nov 21 '05 #3
David,

"David A. Osborn" <do********@hotmail.com> schrieb:
I am current writing a console program that takes two file paths as command
line input. I get the command line input using the following code:

parameter = Split(Command())
input = parameter(0)
output = parameter(1)

Unforunately this method does not handle embedded spaces in the file
paths, for example C:\Documents and Settings\Administrator. Is there a
simple way to handle this?


\\\
Public Module Program
Public Sub Main(ByVal Args() As String)
For Each Arg As String In Args
Console.WriteLine(Arg)
Next Arg
End Sub
End Module
///

In the project properties, select 'Sub Main' as startup object.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #4
David,

Why not tell to do it as we self do.

path1,path2

And split than on the comma?

Just my thought,

Cor
Nov 21 '05 #5
"Cor Ligthert" <no************@planet.nl> schrieb:
Why not tell to do it as we self do.

path1,path2

And split than on the comma?


Do you know any other application that uses "," as a path separator? How
would that work with a command-line like 'Goo.exe /file:"C:\Bla Bla\Bla.txt"
/output:"C:\Foo Foo\Foo.txt"'. I think that "," would confuse the user...
:-).

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

Nov 21 '05 #6
Herfried,

Do you know any other application that uses "," as a path separator? How
would that work with a command-line like 'Goo.exe /file:"C:\Bla
Bla\Bla.txt" /output:"C:\Foo Foo\Foo.txt"'. I think that "," would
confuse the user... :-).


You probably still use a horse to go from A to B, there are more
alternatives now, that is because somebody started to do it in another way.

:-)

The alternative is someting as
/I:'Inputpath' /O:'Outputpath'

However how many endusers are still commandline users so a simple

command or command /? or command /h or any one that does not be conform the
needed, can give a help file what exactly describes how it should be done
and than will in my opinion almost everybody understand it when the text is
"Inputpath , (include comma) Outputpath"

Just my idea

Cor
Nov 21 '05 #7
David,
In addition to the other comments:

You can use Sub Main(Args() as String) as the other suggested, or you can
use Environment.GetCommandLineArgs if you need the parameters far removed
from the Main routine.

Alternatively you can use the CommandLineToArgvW win32 api, unfortunately I
do not have the Declare statement. I would however only resort to using
CommandLineToArgvW directly where I needed to parse a string being input by
the user into a "command line". Searching groups.google.com brings up a
number of possibilities for samples.

Hope this helps
Jay
"David A. Osborn" <do********@hotmail.com> wrote in message
news:5F6Td.48045$4q6.18156@attbi_s01...
I am current writing a console program that takes two file paths as command
line input. I get the command line input using the following code:

parameter = Split(Command())
input = parameter(0)
output = parameter(1)

Unforunately this method does not handle embedded spaces in the file
paths, for example C:\Documents and Settings\Administrator. Is there a
simple way to handle this? From my command prompt experience I know that
paths like this are usually passed in quotes, but the method above still
breaks it apart at the spaces. Does vb.net have a built method to handle
this or do I need to do some sort of character checking loop that looks
for the quotes?

Nov 21 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by Samantha Smit | last post: by
34 posts views Thread by Roman Mashak | last post: by
6 posts views Thread by evantri | last post: by
4 posts views Thread by Keith Hughitt | last post: by
1 post views Thread by XIAOLAOHU | last post: by
1 post views Thread by ZEDKYRIE | last post: by

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.