KBEC-00338 How to start an application in a step and keep it running after the step completes?

Article ID:360033190331
1 minute readKnowledge base

Problem:

You want to start an application in a step and keep it running after the step completes. However when you call the application directly (for example, notepad.exe), the step does not complete until the application exits.

Solution:

Use the following code to start the application and set the step shell to "ec-perl".

use ElectricCommander;
use Win32;
use Win32::Process;
$ApplicationName = 'C:\\Windows\\System32\\notepad.exe';
$CommandLine = 'notepad';

$CreateOptions = NORMAL_PRIORITY_CLASS | DETACHED_PROCESS;
Win32::Process::Create($ProcessObj,$ApplicationName,$CommandLine,
    0, # Don't inherit.
    $CreateOptions,
    ".") # current dir.
    or die print_error();

print "$ApplicationName is still running.\n";

sub print_error {
    print Win32::FormatMessage( Win32::GetLastError() );
}

This example starts notepad.exe and it continues running while the step completes.

NOTE:

You may need to start the agent in interactive mode if you want to start an application with GUI. Please refer to this article for more details.

Applies To:

All ElectricCommander and CloudBees CD (CloudBees Flow) agents in Windows platform.

This article is part of our Knowledge Base and is provided for guidance-based purposes only. The solutions or workarounds described here are not officially supported by CloudBees and may not be applicable in all environments. Use at your own discretion, and test changes in a safe environment before applying them to production systems.