Is it possible to return the arguments from the processPath
in this example?
This might make more sense, sorry.
Dim processName As String
Dim processPath As String
If processName = "cmd" Then
Dim arguments As String() = Environment.GetCommandLineArgs()
Console.WriteLine("GetCommandLineArgs: {0}", String.Join(", ", arguments))
End If
A simple (and clean) way to accomplish this would be to just modify your Sub Main
as follows,
Sub Main(args As String())
' CMD Arguments are contained in the args variable
Console.WriteLine("GetCommandLineArgs: {0}", String.Join(", ", args))
End Sub
The VB.Net solution to your problem is to use Command()
VB.Net function when you search to display command's line of currently executed process.
Sub Main(args As String())
Dim sCmdLine As String = Environment.CommandLine()
Console.WriteLine("CommandLine: " & sCmdLine)
Dim iPos = sCmdLine.IndexOf("""", 2)
Dim sCmdLineArgs = sCmdLine.Substring(iPos + 1).Trim()
Console.WriteLine("CommandLine.Arguments: " & sCmdLineArgs)
End Sub
The first outpout will display the complete command's line with name of program.
The second output will display only the command's line without program's name.
Using args
is C/C++/C#/Java technic.
Using CommandLine()
function is pure VB and is more intuitive because is return command's line as typed by user without supposing that arguments are type without blank.
Example:
LIST-LINE 1-12, WHERE=(20-24='TYPES'),to-area=4
LIST-LINE 1 - 12, WHERE = ( 20-24 = 'TYPES' ) , to-area = 4
In this command's syntax, arguments are separated by COMMA and not by spaces.
In this case, it is better to not use args
technic that is more linked to C and Unix where command syntax accepts arguments separated by space !
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With