Start a Run Configuration from code

I have a RunConfiguration and I'd like to start it by clicking a button in a toolwindow that I created.
By looking at the code, I understood that first I should set the configuration as selected, e.g.

 

final RunnerAndConfigurationSettings settings = ...// here get the runner and  conf settings
final RunManager runManager = RunManager.getInstance(project);
runManager.setSelectedConfiguration(settings);

Then, I wonder how I can start the Run Configuration that I get from

final RunConfiguration runConfiguration = settings.getConfiguration();

Any suggestion?

2 comments
Comment actions Permalink
Official comment

See com.intellij.execution.runners.ExecutionUtil#runConfiguration()

Comment actions Permalink

Would it work something like: 

final ProgramRunner runner = DefaultJavaProgramRunner.getInstance();
final Executor executor = DefaultRunExecutor.getRunExecutorInstance();
runner.execute(new ExecutionEnvironment(executor, runner, runnerAndConfigurationSettings, project), null);
0

Please sign in to leave a comment.