繁体   English   中英

通过命令提示符运行表单应用程序并向其发送命令

[英]Run forms Application through command prompt and send commands to it

我在 VB 中有一个 Windows 窗体工具,我已经研究了一段时间了。 现在我希望能够通过命令提示符访问所有控件并返回值,以便我能够通过 Azure 使用它并基本上使应用程序成为黑匣子。

所以这就是我认为我应该这样做的方式。

1 - 在我的项目中,我创建了第二个解决方案,一个 C# Windows 命令行框架。

2 - 我将以下脚本添加到第二个项目中以运行 win 表单

using EnabledTest;
using System;
using System.Windows.Forms;

namespace Command_lineStartup
{
    internal class Program
    {
        private static frmMain MainForm;

        [STAThread]
        private static void Main(string[] args)
        {
            if (args.Length > 0)
            {
                // Command line given, display console

            }
            else
            {
                AllocConsole();
                ConsoleMain(args);
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(MainForm = new frmMain());
                GUI(); 
            }
        }

        private static void ConsoleMain(string[] args)
        {
            Console.WriteLine("Command line = {0}", Environment.CommandLine);
            for (int ix = 0; ix < args.Length; ++ix)
                Console.WriteLine("Argument{0} = {1}", ix + 1, args[ix]);
            // Console.ReadLine();
        }

        [System.Runtime.InteropServices.DllImport("kernel32.dll")]
        private static extern bool AllocConsole();

        public static void GUI()
        {
            Console.WriteLine("Testing version 1 :");
            Console.WriteLine("Enter Project File path to open, Project must be a .mmp file");
            string Path = Console.ReadLine();
            MainForm.LoadProject(Path);
        }
    }
}

但是,我不认为这是正确的方法。 当我使用 C:\\TFS\\Enabled Test\\Command-lineStartup\\bin\\Debug\\Command-lineStartup.exe 通过 CMD 运行控制台应用程序时”

我没有按照我希望的方式工作。

所以我的问题是。 我会以正确的方式解决这个问题吗? 如果是这样,我在这里做错了什么

有更容易的方法吗?

所以我最终找到了一种方法。 通过 CMD 运行应用程序时,提供的参数可以使用

 Dim cla As String() = Environment.GetCommandLineArgs()

然后对于提供的每个参数,您都可以用它做一些事情。 例如,

 If cla.Length > 1 Then
        'cla(0) is the executable path.
        'cla(1) is the Path to the project
        If Not IsIDE() Then WCLicenseIsLicensed("Application", True)
        Me.Text = Application.ProductName
        mblnLoaded = True

        LoadProject(cla(1))

        TreeVieuwSystem.Nodes(cla(2)).Expand()
        TreeVieuwSystem.SelectedNode = TreeVieuwSystem.Nodes(cla(2)).Nodes.Find(cla(2) & "\" & cla(3), True).First
        NodeSelected()
        If cla(2) = "Test Plans" Then
            TheWindowThatAllowsYouToEditTheObject.RunTestPlan()
        ElseIf cla(2) = "Tests" Then
            TheWindowThatAllowsYouToEditTheObject.RunTest(False)
        End If
    Else

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM