473,498 Members | 1,942 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6594
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
6131
by: Robert | last post by:
I am using the php4-cgi Debian package which is based on PHP 4.3.4. I have problems when running php4 on the command line. If I say something like $ php4 index.cgi a number of variables...
13
4734
by: Samantha Smit | last post by:
Hi, I am trying to create a simple asp page that has one command button that updates a database. The URL of the page is like this: http://MyServer.com/Update.asp?UserName=Tom My asp code is...
2
4164
by: SunRise | last post by:
Hi I am creating a C Program , to extract only-Printable-characters from a file ( any type of file) and display them. OS: Windows-XP Ple help me to fix the Errors & Warnings and explain...
17
7880
by: comp.lang.tcl | last post by:
The TCL command I am using will do a command-line action on a PHP script: set cannotRunPHP I have to do it this way as both the TCL script and the PHP script run as CLI. However, "info.php"...
34
6819
by: Roman Mashak | last post by:
Hello, All! I'm implementing simple CLI (flat model, no tree-style menu etc.). Command line looks like this: <command> <param1> <param2> ... <paramN> (where N=1..4) And idea is pretty simple: ...
6
5593
by: evantri | last post by:
I am developing a program that prompt the input from the command line argument. For example, this is the lists of command line arguments that I want to include: -fish -cat -dog -animal All...
2
2898
by: explode | last post by:
I made nova oledbdataadapter select update insert and delete command and connection veza. dataset is Studenti1data, I made it by the new data source wizard,and made datagridview and bindingsource...
11
11879
by: Jon Davis | last post by:
Does anyone know why using System.Diagnostics.Process to "wrap" a console application does not always transmit the I/O, depending on what processes you're trying to "consume"? PowerShell, for...
4
7418
by: Keith Hughitt | last post by:
Hi all, I am using someone else's script which expects input in the form of: ./script.py <arg1arg2 I was wondering if the angle-brackets here have a special meaning? It seems like they...
0
7165
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,...
1
6885
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...
0
7379
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...
1
4908
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...
0
4588
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
3093
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
3081
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1417
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 ...
1
656
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.