简体   繁体   English

如何在命令行中使用传递参数

[英]how to use passing arguments in command line

I want to use my passing arguments in command line.My program is to generate latex file, from a lot of latex files using check boxes.我想在命令行中使用我的传递参数。我的程序是使用复选框从许多乳胶文件中生成乳胶文件。 And later to generate configuration files in which I save and load my chosen files, this configuration file is made by JSON format.稍后生成配置文件,我在其中保存和加载我选择的文件,这个配置文件是由 JSON 格式制作的。 After that I am making a Event load handler to keep my chosen check boxes checked as written in JSON file.之后,我正在制作一个事件加载处理程序,以保持我选择的复选框在 JSON 文件中被选中。 So another step I want to make is using command line use my porgram.exe and my file.json, then my program.exe should keep check boxes checked as written in JSON format( It is working when running program, but I want to work it in command line, for example cd c:\\dir\\program.exe file.json ).所以我想做的另一个步骤是使用命令行使用我的 porgram.exe 和我的 file.json,然后我的 program.exe 应该保持以 JSON 格式编写的复选框(它在运行程序时工作,但我想工作它在命令行中,例如cd c:\\dir\\program.exe file.json )。 How should I use those passing arguments in command line?我应该如何在命令行中使用这些传递参数? here is my Load event handler code:这是我的 Load 事件处理程序代码:

private void Form1_Load(object sender, EventArgs e)
        {
            var cmdArgs = Environment.GetCommandLineArgs();

            if (cmdArgs.Length==1)
            {
                MessageBox.Show("None file loaded as parameter");
            }
            if (cmdArgs.Length==2)
            {
                MessageBox.Show("JSON file is not loaded as parameter");
                var dconfFilename = cmdArgs[1];
                LoadConfig(dconfFilename);
            }
        }

I found hard times to making it work in command lines.我发现很难让它在命令行中工作。 So I am asking your help or offers, how should I make it work.所以我在寻求你的帮助或提议,我应该如何让它发挥作用。

Thanks.谢谢。

Please describe the error messages or results you get on command line.请描述您在命令行上得到的错误消息或结果。 What should the command cd c:\\dir\\program.exe file.json do?命令cd c:\\dir\\program.exe file.json该做什么? The command cd is for changing directory to the entered path in argument.命令cd用于将目录更改为参数中输入的路径。 You should try to call c:\\dir\\program.exe file.json , isn't it?你应该尝试调用c:\\dir\\program.exe file.json ,不是吗?

c:
cd c:\dir\
program.exe file.json

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

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