Written to command line via Lua, command line reading via C#

Asked

Viewed 74 times

2

I was in need of some help with a code on moon, to generate parameters for the command line, and then collect them by another application, only in C#, to be more specific, I want to run a virtual keyboard C#, and in this execution I want to send the parameters of the coordinates from where it will appear by moon, that is, if I can generate the numbers of X and Y to the command line by moon and collect them by C#, I can handle the screen position.

The current code that had found by moon is:

local X = 20
local Y = 50

os.execute([[C:\\Users\\Public\\Documents\\netcoreapp3.1\\WindowsFormsApp2.exe X Y]])

It simply runs my keyboard and maybe generates the arguments of X and Y, but I don’t know how they are being treated.

What about the Code in C#, I have as a basis:

namespace WindowsFormsApp2

{
    static class Program
    {

        [STAThread]
        static void Main(string[] args)
        {

            // Test if input arguments were supplied.
            if (args.Length >= 0)
            {
                Console.ReadLine();
            }



            Console.WriteLine(args.Length);
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Keyboard());
        }
    }
}

But I’m not sure what I’m getting, if anything, from the command line. Someone knows about it and give me a Help?

Obs:

Operating System: Windows 10

     Programa C#: VisualStudio
  • when you run an application passing parameters they will see in the string[] args of the main

  • But do I have to specify the line or something? Maybe a: ;int X = Console.ReadLine();
int Y = Console.ReadLine();

  • In the case instead of int would be string

1 answer

1


Your moon code is not passing the variables X and Y for your C#application, note that you are sending a string, and in it, the characters themselves, not the value contained in the variables. To send the value of the variables you need to concatenate them to the string, you can do this using string format.:

local X = 20
local Y = 50

os.execute(string.format([[WindowsFormsApp2.exe %c %c]], X, Y))

And then in your C# application you can take them as argument from the main method:

static void Main(string[] args)
{
    Console.WriteLine(args[0]); // Imprime o primeiro argumento (X)
    Console.WriteLine(args[1]); // Imprime o segundo argumento (Y)
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.