Jump to content
Sign in to follow this  
bmw74

Pass a console variable at runtime

Recommended Posts

bmw74

Is there a way that I can compile a console (CUI) script, and at execution time, pass variables to be used in the script? For example:

C:\Testscript.exe <machine> <username> <password>

When this is entered, the script will take the values of <machine>, <username> and <password>, and use them inside the script for processing.

I have looked around the forum but so far I haven't found what I need.

Thanks you!

Share this post


Link to post
Share on other sites
bmw74

It's all inte the helpfile, check the page "Command Line Parameters", what you want to use is either $CmdLine or $CmdLineRaw

Awesome... I looked for functions and macros, but didn't come across this special array in the help file

Thanks for your help!

Share this post


Link to post
Share on other sites
bmw74

For anyone that is interested, here is how I implemented it:

If $cmdline[0] <> 0 Then
    For $i = 1 To $cmdline[0]
        Switch $cmdline[$i]
            Case "-u"
                $username = $cmdline[$i+1]
            Case "-p"
                $password = $cmdline[$i+1]
        EndSwitch
    Next
EndIf

When you compile it, it will check for the following format:

c:\<compiled_program.exe> -u <username> -p <password>

Thanks for all the help!

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.