How do you input command line arguments in IntelliJ IDEA?
Solution 1
Windows, Linux, some Macs:
ALT+SHIFT+F10, Right, E, Enter, Tab, enter your command line parameters, Enter. ;-)
Mac with "OS X 10.5" key schema:
CTRL+ALT+R, Right, E, Enter, Tab, enter your command line parameters, Enter.
Solution 2
There's an "edit configurations" item on the Run menu, and on the pull-down to the left of the two green "run" and "debug" arrows on the toolbar. In that panel, you create a configuration with the "+" button in the top left, and then you can choose the Class containing main(), add VM parameters and command-line args, specify the working directory and any environment variables.
There are other options there as well: code coverage, logging, build, JRE, etc.
Solution 3
If you are using intellij go to Run > Edit Configurations
menu setting. A dialog box will appear. Now you can add arguments to the Program arguments
input field.
Solution 4
Example I have a class Test:
Then. Go to config to run class Test:
Step 1: Add Application
Step 2:
You can input arguments in the Program Arguments textbox.
Solution 5
We cannot go into Terminal and give in the good old java Classname arg1 arg2 arg3
We'll have to edit the run configuration.
Step 1 : Take the Run menu
Step 2 : Select Edit Configurations
Step 3 : Fill the Program arguments field
After that, the arguments will be inserted to the end of the command that IntelliJ creates whenever you run the program :)
Related videos on Youtube
![sungkwangsong](https://i.stack.imgur.com/0r5wX.jpg?s=256&g=1)
sungkwangsong
Updated on March 31, 2022Comments
-
sungkwangsong over 2 years
I usually input command line arguments in Eclipse via run configuration. But I don't know how do achieve the same task in IntelliJ IDEA.
-
SMPH about 10 yearsThis is how I run in commandline
$gradle cucumber -Ptags=@Cal -Penv=dev1
. I entered vales underEdit Config.. > Program Arguments
as--tags "@Cal" "env=dev1"
. I noticed@Cal
worked andenv=dev1
doesn't work. -
Maytham Fahmi almost 9 years@PanCrit In my console when I do
java MyClass < someFileName.txt
it works, but when I add< someFileName.txt
to program arguments in intelliJ, it does returnError: Could not find or load main class <
Any idea how to solve it? -
michaelsnowden almost 8 yearsSame thing but start with CTRL+ALT+D for debug configuration on OS X 10.5+ schema.
-
Kyung Lee almost 8 yearsWhat if I wanna use a redirect symbol? For example, $ javac Filter WhiteList.txt < TotalList.txt, how can I run this in Intellij just like command lines?
-
Isinlor over 5 yearsTIL that we can use variables in program arguments of run configuration: youtrack.jetbrains.com/issue/IDEA-74031 It is possible for example to use the current file path as an argument or just make a prompt.
-
Kalle Richter over 5 yearsDuplicate of an existing ealier answer.
-
Nowaker over 3 years@RossoTheMan I mean the key on the keyboard that's usually located between W and R.
-
PanCrit almost 3 years@maytham-ɯɐɥʇʎɐɯ, I wouldn't expect "< filename" to work in intelliJ, since that's explicitly shell syntax for a redirect to stdIn. IntelliJ would only be expecting to handle arguments that the program itself knows how to interpret. Is there any chance the program takes the name of input files as a parameter? That would be supported.