31

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?

3 Answers 3

23

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.

Sign up to request clarification or add additional context in comments.

Comments

23

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).

4 Comments

Thanks for the feedback Michal, tried this and it seems like the run just hangs/dies and I can't re-run unless I re-open intelliJ. In the config for the external tool, is there anything else you set other than the $Prompt$ param? Did you leave the Program and Working Directory fields blank?
Sorry for late reply, busy days. You're right - I saw it prompting for parameter and assumed it works... please see my edited answer, this is all I could think of for now.
This works only for a single $Prompt$. Do you know if it's possible to have multiple prompts and how? Thanks
@maricn Maybe a bit late, but try: $Prompt$ $Prompt$, this gets a bit annoying when you need a lot of arguments or an unknown amount of argument, perhaps then create a fallback to split the first argument based on spaces
3

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.