Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Waiting for the process to exit
#1
Hi,
I encountered a problem, described as follows:
 
1. A.exe is a resident process, It is displayed continuously in the Task Manager without a GUI interface
2. B.exe relays the command line to A.exe and exits immediately! Then a new A.exe process will be generated, and the process will exit after execution is completed
3. But B.exe There is no provided parameter for waiting for New A.exe exit

With the following PowerShell code, I can achieve waiting for the new A.exe to exit. How achieve the same effect in QM?

Thank you in advance for any suggestions and help.
David

Powershell Code:
Code:
Copy      Help
$relaysProgramPath = "C:\B.exe"
$arguments = '/start "My arg"'
Start-process -FilePath $relaysProgramPath -ArgumentList $arguments

# Set the upper limit of loop attempts and the interval time (second)
$maxAttempts = 30
$interval = 1

#Loop to check the number of processes, maximum 30 attempts
for ($i = 1; $i -le $maxAttempts; $i++)
{
    # Get the number of "A.exe" processes
    $processCount = (Get-process -Name "A").Count
    
    # Check the number of processes
    if ($processCount -le 1)
    {
        # If the number of processes is less than or equal to 1, break the loop
        break
    }
    
    # Wait for the specified interval time
    Start-Sleep -Seconds $interval
}
"New A.exe has exited"
#2
Hi, I don't have QM and have never used it, but if you hand the task off to LA, maybe you could use this (untested, no way to test), and apologies if it's a wild goose chase. (I think the required 'using' directives are already global, but I'm not sure.)
 
Code:
Copy      Help
string relaysProgramPath = @"C:\B.exe";
string arguments = "/start \"My arg\"";
Process.Start(relaysProgramPath, arguments);

// Set the upper limit of loop attempts and the interval time (in seconds)
int maxAttempts = 30;
int interval = 1;

// Loop to check the number of processes, maximum 30 attempts
for (int i = 1; i <= maxAttempts; i++) {
    // Get the number of "A.exe" processes
    Process[] processes = Process.GetProcessesByName("A");
    int processCount = processes.Length;
    
    // Check the number of processes
    if (processCount <= 1) {
        // If the number of processes is less than or equal to 1, break the loop
        break;
    }
    
    // Wait for the specified interval time
    Thread.Sleep(interval * 1000);
}

print.it("New A.exe has exited");
#3
@burque505
Thanks for your help, it can be successfully executed in LA!

I want to package code in QM and generate exe 
 to efficiently achieve my goals, it seems that only use QM code (powershell startup is slow)

Using QM, there may be a more elegant solution. I tried to wait for the handle, but it was unsuccessful


Forum Jump:


Users browsing this thread: 1 Guest(s)