Dnl_
Dnl_

Reputation: 65

command line to wait for input and then process next step

I am writing a batch script to automate some processes. this process runs a few different tools by stages, those tools creates the input necessary to run the next stage.

In one of the stages basically I open an .exe file and call a powershell file to simulate the "enter key" press, so far so good, it opens the tools and it starts to run run it, however what happens is that command line executes the next stage without waiting for the .exe file to finish, which is a important step thus that process creates the input for the next stage.

the command line I use is:

START /WAIT powershell -command .\bat.ps1

which runs this powershell script

[System.Diagnostics.Process]::Start("C:\folder\file.exe", "C:\temp\TestProject1\TestProject1.pjs /run /exit /SilentMode")

$wshell = New-Object -ComObject wscript.shell;
$wshell.AppActivate('title of the application window')
Sleep 1
$wshell.SendKeys('~')

I would like to know if there is a workaround that makes me wait till the .exe file finish running, and then start the new stage.

thanks for your help

Upvotes: 2

Views: 2850

Answers (2)

Dnl_
Dnl_

Reputation: 65

I found a workaround, that partially responds to my question.

I put the START /WAIT command after the powershell command, so while the .exe is running the next stage is on waiting, however I will have to press "y" to continue the process once the .exe file is finished, which is a start.

Thanks once again

Upvotes: 1

No Refunds No Returns
No Refunds No Returns

Reputation: 8336

Have you tried using the Start-Process cmdlet and including the -Wait parameter in lieu of a direct call to Start()?

From your powershell prompt try help start-process to see if some of the other parameters like -NoNewWindow would also be useful to you.

Upvotes: 0

Related Questions