Hack Forums
[.NET] Determine CLI arguments? - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Determine CLI arguments? (/showthread.php?tid=6162887)



Determine CLI arguments? - VUEDUE - Jul 10, 2021

I want to produce a script that utilizes command-line arguments. So far I have this:
Code
Dim clArgs() As String = Environment.GetCommandLineArgs()
        If clArgs.Count <= 1 Then
            Environment.Exit(0).
        End If
Obviously if the user were to double-click the executable, it will exit since it wasn't called from the CLI w/ the appropriate arguments.

At this point however, I want to establish this synatx:
Code
my_program.exe -h http://www.example.com -m GET -r -t 50
Basically I'm trying to get and values following -h (for host), -m (for method), and then the -t (for threads).


I assume I would have to determine their index, right? I'm having trouble getting the values and setting them in global variables. If anyone could help me I would greatly appreciate it <3


RE: Determine CLI arguments? - HFDone - Jul 10, 2021

https://docs.microsoft.com/en-us/dotnet/api/system.environment.getcommandlineargs?view=net-5.0


RE: Determine CLI arguments? - VUEDUE - Jul 11, 2021

(Jul 10, 2021 01:52 PM)HFDone Wrote:  https://docs.microsoft.com/en-us/dotnet/api/system.environment.getcommandlineargs?view=net-5.0

So I comprehend that. If you follow the link you posted, in the example it shows the user how to loop through the values inputted via CLI. I get that. That's not my issue. I'm having trouble determining the order of what was posted. So if the user throws the -m switch, I want to know if the user inputted either GET or POST (one of two http methods) and set that value as a string variable. That's what I'm stuck on. I'm lost on how I would even begin.


RE: Determine CLI arguments? - HFDone - Jul 11, 2021

you have args array check them
if args(1) = "-m" then ... check args(2) value


RE: Determine CLI arguments? - VUEDUE - Jul 11, 2021

(Jul 11, 2021 06:44 AM)HFDone Wrote:  you have args array check them
if args(1) = "-m" then ... check args(2) value

Ahhh, I see. I'll give that a shot. Thanks!