C# 控制台应用程序传递参数

发布于 2024-12-15 20:37:07 字数 326 浏览 3 评论 0原文

我到目前为止:

ProcessStartInfo procInfo = new ProcessStartInfo(@"C:\a\a.exe");
procInfo.CreateNoWindow = true;
procInfo.Arguments = "01";
procInfo.Arguments = user_number;
procInfo.Arguments = email;
Process.Start(procInfo);

但它只传递一个参数(是最后一个要覆盖的参数),我如何传递多个参数,控制台上的 args 是一个数组,这一定意味着我可以传递多个参数?

I got this far:

ProcessStartInfo procInfo = new ProcessStartInfo(@"C:\a\a.exe");
procInfo.CreateNoWindow = true;
procInfo.Arguments = "01";
procInfo.Arguments = user_number;
procInfo.Arguments = email;
Process.Start(procInfo);

But it only passes one argument (being the last one to overwrite), how do I pass more then one argument, the args on the console is an array, this must mean i can pass more then one argument?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

等风也等你 2024-12-22 20:37:07

您需要传递一个以空格分隔的参数字符串:

procInfo.Arguments = "01 " + user_number + " " + email;

同样的事情,使用以下格式:

procInfo.Arguments = string.Format("{0} {1} {2}", "01", user_number, email);

You'll want to pass a single string of space-separated arguments:

procInfo.Arguments = "01 " + user_number + " " + email;

The same thing, using a format:

procInfo.Arguments = string.Format("{0} {1} {2}", "01", user_number, email);
小傻瓜 2024-12-22 20:37:07

试试这个..

procInfo.Arguments = "01 " + user_number + " " + email; 

try this ..

procInfo.Arguments = "01 " + user_number + " " + email; 
只是一片海 2024-12-22 20:37:07

每个人都对只需要连接即可。只是一种风格上的事情,但您可以使用 String.Join 使传递参数更加优雅:

        string[] argv = {"01", user_email, email};
        ProcessStartInfo procInfo = new ProcessStartInfo(@"C:\a\a.exe");
        procInfo.CreateNoWindow = true;
        procInfo.Arguments = String.Join(" ", argv);
        Process.Start(procInfo);

Everyone's right about just needing to concatenate. Just a stylistic thing but you can use String.Join to make passing the arguments a bit more elegant:

        string[] argv = {"01", user_email, email};
        ProcessStartInfo procInfo = new ProcessStartInfo(@"C:\a\a.exe");
        procInfo.CreateNoWindow = true;
        procInfo.Arguments = String.Join(" ", argv);
        Process.Start(procInfo);
忆沫 2024-12-22 20:37:07

将您的参数连接成一个由空格分隔的字符串?或者,您可以在每个参数之前使用某种标识符,并让 .exe 应用程序解析该字符串。

Concatenate your arguments into a single string that a delimited by a space? Or you could use some sort of identifier before each argument and have the .exe application parse the string.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文