473,542 Members | 2,057 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\Admini strator. 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 6603
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********@hot mail.com> wrote in message
news:5F6Td.4804 5$4q6.18156@att bi_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\Admini strator. 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********@hot mail.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\Admini strator. 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.WriteLi ne(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.Get CommandLineArgs if you need the parameters far removed
from the Main routine.

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

Hope this helps
Jay
"David A. Osborn" <do********@hot mail.com> wrote in message
news:5F6Td.4804 5$4q6.18156@att bi_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\Admini strator. 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
6135
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 are not initialized. For example, $HTTP_GET_VARS is not set. To get it set, here's my workaround:
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 like this: %@ Language=VBScript %> <!--#include file="includes/openconnection.asp"-->
2
4171
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 how to use Command-Line Arguments inside C program.
17
7888
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" requires user input to run; this causes the TCL script calling the PHP script to hose up and die. Is there a way I can do this so that the TCL...
34
6822
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: 1) get whole string of input line 2) preset table of strings matching <command> 3) preset table of function calls
6
5601
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 command line arguments can be in any order, BUT -animal must be in the last command line argument otherwise error message displayed Let's say this...
2
2910
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 draging Table1 to Form2. The select command works fine, but when I change the data and call update command I get a syntax error: ...
11
11894
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 example, does not seem to process any I/O through the Process object. I know that in the case of PowerShell there are better ways to "wrap" the...
4
7425
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 specify an input and output stream to use in place of the console. I could not
0
7392
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7330
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...
0
7670
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...
0
5867
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...
1
5246
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...
0
4880
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...
0
3380
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...
0
3376
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
620
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...

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.