Creating a simple command line console app in Visual Studio 2019

Isaac

Lifelong Learner
Local time
Today, 00:26
Joined
Mar 14, 2017
Messages
11,834
Hello all,
I am trying to create a console app in visual studio 2019, which will eventually become an .exe that can be ran using command line programming, i.e., someone can open the command prompt and put in a command that contains the path to the exe with 2 different parameters.

I already have the successful .net code written but it's in the form of an SSIS script task.

This is in VB.net only.

I'm having some trouble understanding how to create a console app which can be truly automated via command line and take input param's.

I see various tutorials from MS but I am not readily finding a good one that focuses on the user being able to command line run the program using input switches - rather, they prompt the user at run-time for input, which I don't want to do, as I want it to be able to be automated.

Does anyone know a tutorial or site or set of instructions that may get me to the end point rather quickly? I already have working .net code for the task at hand, just need to figure out how to turn it into an exe that someone can run with command line something like

pathtoexe -filepath thefilepath -chunksize 600
 
Ok I kinda figured it out thanks to some web pages - you just assume the input args() is a string array, space delimited, meaning string array for use on the inside and space-delimited for 'how to use' on the outside.

pathtoexe "firstargvalue" "secondargvalue"

and Bazinga! that's it! Cool stuff, having fun on this one, as fun goes..
 
you just assume the input args() is a string array, space delimited
That doesn't sound right. You should be able to pass numeric arguments.

I've not included parameters in a console app before but I expect they would be individually declared on Main().
 
I mean the args() is a string array inside the .net

Got it working!

They're not individually declared, they just come in from the outside as args() string array on the inside
 
Here's a simple console app we created for copying folders and files. It accepts two command line arguments, e.g.

Code:
FolderCopy S:\HyperV\Images\Ubuntu2510.vhdx F:\

Code:
Imports Microsoft.VisualBasic.FileIO
Imports System.Environment
Module Module1

    Public Sub Main()

        If GetCommandLineArgs().Count <> 3 Then
            Console.WriteLine("Missing source or destination path, or too many arguments")
            Exit Sub
        End If

        Dim strSourcePath As String = GetCommandLineArgs(1)
        Dim strDestinationPath As String = GetCommandLineArgs(2)

        My.Computer.FileSystem.CopyDirectory(strSourcePath, strDestinationPath, UIOption.AllDialogs)

    End Sub

End Module
 
Last edited:
A little while a go I wrote a VB.Net console app to generate QR code .png files from data. I can just pass in the payload and filename, and it integrates seamlessly into the MS Access project. I even found a way to force it to run synchronously so I can call if from Report.Detail_Format() events and write/present .png files for each row in a report.
So yeah, this is absolutely a functional pattern, and easily integrated as a service in an MS Access project.
 
A little while a go I wrote a VB.Net console app to generate QR code .png files from data. I can just pass in the payload and filename, and it integrates seamlessly into the MS Access project. I even found a way to force it to run synchronously so I can call if from Report.Detail_Format() events and write/present .png files for each row in a report.
So yeah, this is absolutely a functional pattern, and easily integrated as a service in an MS Access project.
That's really cool. I've done one console app, it was to split large files into smaller files (for loading into AWS s3 bucket with file size limitations)
Then, of course, the person I made it for never used it - said they found another way they preferred. But at least I got some practice.
 
the person I made it for never used it - said they found another way they preferred
It happens, been there too. There's lots of things you can do with vb.net to extend Access app functionality. I found vb.net's syntax similar to vba, and that makes it easier to learn.
 
Last edited:

Users who are viewing this thread

Back
Top Bottom