Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make IntelliJ prompt me for command line arguments

In Eclipse, you can provide the program argument ${string_prompt} in your run configuration to have it prompt for the command line arguments.

Is there a way to do this in IntelliJ?

like image 715
Carl Karawani Avatar asked Dec 19 '13 18:12

Carl Karawani


People also ask

How do I pass command line arguments in IntelliJ?

From the main menu, select Run | Edit Configurations or choose Edit Configurations from the run/debug configurations selector on the toolbar. In the Run/Debug Configurations dialog that opens, select a configuration where you want to pass the arguments. Type the arguments in the Program arguments field.

How do you pass a command line argument?

If you want to pass command line arguments then you will have to define the main() function with two arguments. The first argument defines the number of command line arguments and the second argument is the list of command line arguments.

How do I get terminal in IntelliJ?

From the main menu, select View | Tool Windows | Terminal or press Alt+F12 .


3 Answers

Edit:

This may be a bug in IDEA, the solution that I first posted (you can see it below) causes Intellij to hang after entering parameter.

I couldn't come up with a solution to this, but here's a little trick: you can scroll to the very bottom of Run/Debug configuration screen and in "Before launch" section check a checkbox saying "Show this page".

From now on you'll be automatically shown configuration screen when you choose to Run/Debug your application and there you can enter any parameters you want... It's not that comfortable, but at least a little bit more automatized.

Previous answer:

This is a bit more complicated with Intellij:

  • go to Settings -> External Tools -> Add (green plus)
  • in Parameters line click Insert macro -> Prompt (you can simply type in $Prompt$ as well)
  • save settings
  • go to Run -> Edit Configurations...
  • in Before Launch section choose Run External Tool and select tool that you've created

That should suffice (works in IDEA 12.1.6).

like image 197
Michał Rybak Avatar answered Oct 23 '22 14:10

Michał Rybak


Starting from versions 2018.3 and 2019.1, IntelliJ now supports macros in Run configurations. You can use $Prompt$ anywhere in the VM Options, Program arguments, etc. fields, and it will behave just like ${string_prompt} in Eclipse -- it will prompt you for parameters when the configuration is run.

like image 13
Grodriguez Avatar answered Oct 23 '22 14:10

Grodriguez


Based on using Intellij IDEA 2020.3, we can set the configuration to prompt for program arguments at the program arguments field

Right click the program and then choose menu More Run/Debug > Modify Run Configuration

Look for the Program arguments text field

Type $Prompt$ at the Program arguments text field and then click OK

like image 3
Kanda Runapongsa Saikaew Avatar answered Oct 23 '22 12:10

Kanda Runapongsa Saikaew