命令行参数具体是什么?
我一直想问我的大学老师它在 public static void main(String[] args)
中具体做了什么,但我实际上从来没有机会,因为那是上学期的事,我从来没有真正了解过它的作用做什么以及它的重要性是什么,我们只是因为实践而使用。但当我尝试学习 C# 时,出现了此类问题(我试图从 MSDN 教程中学习 C#,但命令行参数的定义并不那么深入和密集)。什么是命令行参数?
I always wanted to ask my college instructor what does it do specifically in public static void main(String[] args)
but I never actually had a chance because it was last term, I never actually what does it do and what its importance, we just use because of practice. but as I try to learn C# these type of question arises, (I am trying to learn C# from the MSDN tutorials but the definition of command line argument is not that depth and dense) . what is a command line argument?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
主可执行文件名之后传递的任何内容:
helloworld.exe arg1 arg2 "arg 3"
在这种情况下,控制台将解释
arg1
和arg2
> 作为前两个参数,"arg 3"
作为第三个参数。 CLI(在本例中为命令行解释器)将使用空格作为分隔符。另请记住,如果可执行文件的路径包含空格:
hello world.exe
那么命令行解释器通常会将
hello
解释为命令,其中world.exe< /code> 作为第一个参数;因此,在这种情况下,引号对于实际描述命令结束和参数开始的位置非常重要。
您的应用程序无法控制如何解析引号;因此,如果您需要拥有自己的参数引用系统(例如,如果您将运行时参数打包到单个命令行参数中),您可能必须构建自己的解析器并使用自己的引用系统;例如使用
'
甚至括号。Anything that is passed after the main executable filename:
helloworld.exe arg1 arg2 "arg 3"
In this case, the console will interpret
arg1
andarg2
as the first two arguments, and"arg 3"
as the third. CLIs (in this case Command Line Interpreters) will use space as a delimiter.Remember also that if the path of the executable contains spaces:
hello world.exe
Then a command line interpreter typically interprets
hello
as the command, withworld.exe
as the first argument; thus in this case the quotes are important to actually delineate where the command ends and the arguments begin.Your application has no control as to how the quotes are parsed; therefore if you need to have your own quoting system for arguments (e.g. if you are packing runtime parameters into a single commend-line argument) you will likely have to build your own parser and use your own quoting system; e.g. use
'
or even brackets.命令行参数是从命令行(“DOS 提示符”)调用时传递给可执行文件的参数,例如
此外,当您将文件扩展名(例如 .foo)与可执行文件关联时,文件名将传递为双击文件时可执行文件的命令行参数。
A command line argument is an argument passed to the executable when invoked from the command line ("DOS prompt"), e.g.
Also, when you associate a file name extension (such as .foo) with your executable, the file name is passed as command line argument to the executable when you double-click the file.
命令行参数是程序调用的字符串。以:
ping computerA
为例。ComputerA
将是ping
的命令行参数。Command line arguments are the Strings that are called with the program. Take for example:
ping computerA
.ComputerA
would be the command line argument forping
.AFAIK,所有 IDE 都支持带有命令行参数的程序。
一个方法
当您开始时,仅调用或
调用
,因为这是预期的。如果你有一个方法,
这些方法不是同一个方法,你会得到一个错误。
AFAIK, All IDEs support program with command line arguments.
When you start, only a method called
or
is called because that is what is expected.
If you have a method
these are not the same method and you will get an error.
这些是您可以在应用程序启动时传递的参数。它们之间用空格分隔。
请参阅此处:http://en.wikipedia.org/wiki/Command-line_interface
These are parameters you can pass your application at startup. They are seperated with spaces.
See here: http://en.wikipedia.org/wiki/Command-line_interface
是的,您向应用程序传递了一些参数。假设我将像这样运行你的程序:
然后
你可以稍后打印出来,或者用作你的程序的变量
Yes, you pass your application some arguments. Say I will run your program like this:
then
you can print out these later on, or use as variables for your program
命令行参数是您在运行程序时提供的参数。就像 java -jar myprogram arg1 arg2 或例如在 java 中运行 java myprogram arg1 arg2 而不是 java myprogram 时。
因此,下面的代码:
输出将为
arg1 arg2
这意味着
第一个参数 = arg1,第二个参数 = arg2
。Command line arguments are those you supply when you run your program. Like
java -jar myprogram arg1 arg2
or for example in java when you runjava myprogram arg1 arg2
instead ofjava myprogram
.So, the below code:
The output will be
arg1 arg2
It means
first argument = arg1 and second argument = arg2
.