473,320 Members | 2,027 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Template for Command-Line utility

I'm fairly new to VS/VB.net. I want to create a command line utility
that uses two parameters, reads a file (first parm), and writes to
another file (2nd parm). Which VS/VB.net template should I use to get
started? Thanks in advance.
Oct 29 '08 #1
6 1389
On Oct 29, 7:01*pm, Phil Hellmuth <bill...@pacbell.netwrote:
I'm fairly new to VS/VB.net. *I want to create a command line utility
that uses two parameters, reads a file (first parm), and writes to
another file (2nd parm). *Which VS/VB.net template should I use to get
started? *Thanks in advance.
Start New Project, Choose "Console Application".

BTW, is all your intention to copy files using like
System.IO.File.Copy?

Thanks,

Onur Guzel
Oct 29 '08 #2
On 2008-10-29, Phil Hellmuth <bi*****@pacbell.netwrote:
I'm fairly new to VS/VB.net. I want to create a command line utility
that uses two parameters, reads a file (first parm), and writes to
another file (2nd parm). Which VS/VB.net template should I use to get
started? Thanks in advance.
You'll want to create a Console application. Your main should probably
look like this:

Public Function Main (ByVal args() As String) As Integer
' args contains all the arguments passed to your application
' assuming that the arguments are correct (you'll want to put
' in validation/parsing code here...

Dim inputFile As String = args(0)
Dim outputFile As String = args(1)

' do cool stuff

' You will most likely want to return an exit code
' 0 means no error, non-zero means a problem - you might
' want to have different codes for different problems, but
' that's up to you. You don't have to do this at all :)
' you could make Main a sub instead of a function, but
' most command line apps return an exit code to the OS -
' so it's a good idea to do the same.
Return AnExitCode
End Function

HTH

--
Tom Shelton
Oct 29 '08 #3
Thanks for your response. This really helps. Unfortunately, I'm stuck
with what I'm trying to do next. I want to see if the files specified
in the arguments exist, using the FileExists function. However, I don't
know what reference to use to import System.File.IO (as I said, I'm new
to this). Next, I want to read each byte in the input file and write it
to the output file if it's less than 128 (ascii). Is this relatively
simple?

Tom Shelton wrote:
On 2008-10-29, Phil Hellmuth <bi*****@pacbell.netwrote:
>I'm fairly new to VS/VB.net. I want to create a command line utility
that uses two parameters, reads a file (first parm), and writes to
another file (2nd parm). Which VS/VB.net template should I use to get
started? Thanks in advance.

You'll want to create a Console application. Your main should probably
look like this:

Public Function Main (ByVal args() As String) As Integer
' args contains all the arguments passed to your application
' assuming that the arguments are correct (you'll want to put
' in validation/parsing code here...

Dim inputFile As String = args(0)
Dim outputFile As String = args(1)

' do cool stuff

' You will most likely want to return an exit code
' 0 means no error, non-zero means a problem - you might
' want to have different codes for different problems, but
' that's up to you. You don't have to do this at all :)
' you could make Main a sub instead of a function, but
' most command line apps return an exit code to the OS -
' so it's a good idea to do the same.
Return AnExitCode
End Function

HTH
Oct 29 '08 #4
On Wed, 29 Oct 2008 11:13:35 -0700, Phil Hellmuth <bi*****@pacbell.net>
wrote:
>Thanks for your response. This really helps. Unfortunately, I'm stuck
with what I'm trying to do next. I want to see if the files specified
in the arguments exist, using the FileExists function. However, I don't
know what reference to use to import System.File.IO (as I said, I'm new
to this). Next, I want to read each byte in the input file and write it
to the output file if it's less than 128 (ascii). Is this relatively
simple?
Have you tried the Help for FileExists? Often there will be a code
snippet to show how it works. Also try googling for sample code.

--

Dennis
Oct 29 '08 #5
On 2008-10-29, Phil Hellmuth <bi*****@pacbell.netwrote:
Thanks for your response. This really helps. Unfortunately, I'm stuck
with what I'm trying to do next. I want to see if the files specified
in the arguments exist, using the FileExists function. However, I don't
know what reference to use to import System.File.IO (as I said, I'm new
to this). Next, I want to read each byte in the input file and write it
to the output file if it's less than 128 (ascii). Is this relatively
simple?
Actually, it is :) Here is some air-code, this untested, and is infact not
likely to work the first try... I might have my indexing off or some minor
syntax issues, but it should be enough to get you started :)

Option Explict On
Option Strict On

Imports System
Imports System.IO

Public Function Main (ByVal args() As String) As Integer
' args contains all the arguments passed to your application
' assuming that the arguments are correct (you'll want to put
' in validation/parsing code here...

Dim inputFile As String = args(0)
Dim outputFile As String = args(1)
Dim anExiteCode As Integer = 0
Dim inBuffer() As Byte = new Byte(2048)
Dim outBuffer() As Byte = new Byte(2048)
Dim bytesRead As Integer = 0
dim bytesWritten = 0

Try
Using inFile As New FileStream(inputFile, FileMode.Open, FileAccess.Read), _
outFile As New FileStream(ouputFile, FileMode.Create, FileAccess.Write)

bytesRead = inFile.Read(inBuffer, 0, inBuffer.Length)
while bytesRead 0
for i as integer = 0 to bytesRead - 1
if inbuffer(i) 128 then
outBuffer(bytesWritten) = inbuffer(i)
bytesWritten += 1
end if
next i
outFile.Write(outBuffer, 0, bytesWritten)
bytesRead = inFile.Read(inBuffer, 0, inBuffer.Length)
end while
End Using
Catch ex As Exception
anExitCode = 1
End Catch

' You will most likely want to return an exit code
' 0 means no error, non-zero means a problem - you might
' want to have different codes for different problems, but
' that's up to you. You don't have to do this at all :)
' you could make Main a sub instead of a function, but
' most command line apps return an exit code to the OS -
' so it's a good idea to do the same.
Return anExitCode
End Function

Anyway, hth

--
Tom Shelton
Oct 29 '08 #6
On 2008-10-29, Phil Hellmuth <bi*****@pacbell.netwrote:
Thanks for your response. This really helps. Unfortunately, I'm stuck
with what I'm trying to do next. I want to see if the files specified
in the arguments exist, using the FileExists function. However, I don't
know what reference to use to import System.File.IO (as I said, I'm new
to this). Next, I want to read each byte in the input file and write it
to the output file if it's less than 128 (ascii). Is this relatively
simple?
Actually, i didn't notice your question about references :) You don't need to
add any additional references - just add the Imports System.IO.

--
Tom Shelton
Oct 29 '08 #7

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

Similar topics

9
by: Sebastian Faust | last post by:
Hi, I have a design problem about which I am thinking now for a while and still couldnt find any help in deja. What I need is something like a virtual function template. I know that this is not...
2
by: Avi Uziel | last post by:
Hi All, I have a linkage problem that I believe related to template instantiation. My environment is Solaris 5.6, Compiler WorkShop 5. I'm building a shared library which use templates. During...
17
by: mrstephengross | last post by:
I've got a 'Command' class whose constructor takes an instance of a template argument T. The constructor then prints out the name of the class T that was passed to it. When I construct the T class...
3
by: moondaddy | last post by:
using vb.net 1.1 I have a datalist and in it's item template I have 2 buttons, 'edit' and 'ShipToThisAddress'. The edit button works fine and it opens up the edit template as it works with the...
3
by: NateDawg | last post by:
I'm reposting this. I'm kinda in a bind untill i get this figured out, so if anyone has some input it would sure help me out. Ok, I’ve noticed a few gridview problems floating around the forum....
0
by: Dorte | last post by:
Hi, I use the gridview control to display data. I use a dataadapter to fill a datatable from an SQL server - the command is a stored procedure. Furthermore I have a couple of template columns...
2
by: Smokey Grindle | last post by:
I have the following on my page... a link button that will send the command name "use" to the command handler and a grid view with the following columns 0 - Template column - just a checkbox...
1
by: toton | last post by:
Hi, Is there any tool for template debugging, during compilation process ? Just like gdb or visual studio debugger do it during program execution, a step by step debug for the program, I am...
4
by: SEliel | last post by:
Hello everyone: I'm programming a custom GridView, adding column by column dynamically. Every column is a TemplateField, and I've made a class hierarchy for each template (TextColumnTemplate,...
1
by: brianrpsgt1 | last post by:
Newbie here.... I have been able to successful pull info from a MySQL DB, get the results and output them in an HTML format using Cheetah to the screen using IDLE. I am doing this on a Windows...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.