可以将名称/值作为参数传递到 Windows 控制台应用程序吗?

发布于 2024-08-12 10:01:03 字数 264 浏览 1 评论 0原文

构建我的第一个控制台应用程序之一。

该控制台应用程序将运行我定义的一些存储过程。我希望能够通过命令行传入参数值。

有什么方法可以传入名称值对吗?例如:

myConsoleApp.exe sproc_GetLastActives, @LastActiveDate - 11/20/2009

我知道如何检索参数值,但我注意到如果我放入 / 或 , ,args[] 就会被分割。如何传入名称值对?

谢谢!

Building one of my first console apps.

This console app will run some stored procedures I'm defining. I would like to be able to pass in parameter values via the command line.

Is there any way to pass in a name value pair? For example:

myConsoleApp.exe sproc_GetLastActives, @LastActiveDate - 11/20/2009

I know how to retreive the parameter values, but I'm noticing that the args[] are split if I put in a / or a ,. How can I pass in name value pair?

Thanks!

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

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

发布评论

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

评论(4

赤濁 2024-08-19 10:01:03

你想把它放在一个字符串中吗?试试这个:(

myConsoleApp.exe "sproc_GetLastActives, @LastActiveDate - 11/20/2009"

即仅添加引号)

斜杠和逗号不应该影响事物,但命令行解析器会按空格分割,除非您引用了它。

Do you want that in a single string? Try this:

myConsoleApp.exe "sproc_GetLastActives, @LastActiveDate - 11/20/2009"

(i.e. just add quotes)

Slashes and commas shouldn't affect things, but the command line parser splits on spaces unless you've quoted it.

扶醉桌前 2024-08-19 10:01:03

此问题有多种解决方案,最常见的是使用“/”或“-”作为参数前缀,并使用 = 将它们与参数分隔开,例如

consoleapp.exe /spname=sproc_GetLastActives /LastActiveDate="11/20/2009"

在代码中,您可以使用 String.Split(arg[i], new char[] {'='}) 来破坏各个参数。

There are several solutions to this problem the most common is to use '/' or '-' to prefix parameters and = to delimit them from their arguments for example

consoleapp.exe /spname=sproc_GetLastActives /LastActiveDate="11/20/2009"

in your code your code you can use String.Split(arg[i], new char[] {'='}) to bust up the individual parameters.

遗弃M 2024-08-19 10:01:03

consoleapp.exe key1 val1 key2 val2

args[] 给出您的 4 个项目,将它们在代码中配对。 :P

consoleapp.exe key1 val1 key2 val2

args[] gives your 4 items, pair them up in your code. :P

污味仙女 2024-08-19 10:01:03

类似于 mykhaylo 的回复,为什么不在一个字符串中传递值:

consoleapp.exe sproc_name key1=value1 "key2=Value With Spaces" key3=value3

然后只需测试 = 符号是否存在并解析它以获取键/值对。

Similar to mykhaylo's response, why not pass in the values at one string:

consoleapp.exe sproc_name key1=value1 "key2=Value With Spaces" key3=value3

Then just test for the presence of the = sign and parse it to get your key/value pair.

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