【问题标题】:How do I launch my app from a bash script passing in a parameter?如何从传递参数的 bash 脚本启动我的应用程序?
【发布时间】:2015-09-24 05:39:15
【问题描述】:

我有一个 C# Windows 窗体应用程序,它执行以下操作:

  1. 显示同步“配置文件”列表
  2. 用户可以选择一个“配置文件”并点击“运行”
  3. “配置文件”信息保存在profiles.xml 文件中并动态编辑

如果我要将它创建为可以从 PowerShell 或命令行执行的 .exe,我将如何对其进行编程以便用户可以指定要运行的配置文件?例如,我希望用户从命令行运行以下命令,而不是单击配置文件并选择“运行”:

sync.exe "profile name or id"

如何编写我的 .exe 以像这样运行以及如何处理传入的 args?

【问题讨论】:

  • 只需查找“C# 命令行参数”即可。这就是你想要的。
  • 是的,谢谢!!!你能把它放在答案中,以便我接受吗?

标签: c# winforms bash powershell


【解决方案1】:

您需要使用命令行参数。要在 C# 中执行此操作,请执行以下操作:

public static void Main(string[] args)
{
    // args are your command-line arguments
    // here we check that there was one argument provided, and show a message if there wasn't
    if (args.Length != 1)
    {
        Console.WriteLine("Usage: sync.exe [profile-name]");
        System.Exit(1);
    }
    string profileName = args[0];
    // do stuff with the profile name
}

【讨论】:

    猜你喜欢
    • 2021-07-11
    • 1970-01-01
    • 2021-02-12
    • 2016-09-16
    • 1970-01-01
    • 2015-01-29
    • 2015-10-21
    • 2011-10-10
    • 1970-01-01
    相关资源
    最近更新 更多