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

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

final RunConfiguration runConfiguration = settings.getConfiguration();

Any suggestion?

Official comment

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

Would it work something like: 

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

Please sign in to leave a comment.