-1

I'm trying to run a powershell script as follows:

Start-Process -FilePath "C:\svn\Services\trunk\Services.In4m.Agent.Host\bin\agent.exe" -Argument --help

Any reason why this could be happening. Also, how to write a script so that the command prompt window does not close immediately?

the_coder_in_me
  • 143
  • 3
  • 15

2 Answers2

1

It looks like the program is ending. If the command just outputs the help text and ends, the window will close upon completion.

Your best bet will be to capture the output from the command and display it out to the user.

& "C:\svn\Services\trunk\Services.In4m.Agent.Host\bin\agent.exe" --help | Write-Host

If you want to open a separate window and wait for the user to hit enter to close it, you could do something like this:

Start-Process 
  -FilePath "powershell.exe" 
  -ArgumentList "& 'C:\svn\Services\trunk\Services.In4m.Agent.Host\bin\agent.exe' --help; Read-Host"

It just depends on what you're trying to achieve.

Scott Kearney
  • 173
  • 10
  • I'm trying to open agent.exe and hold the window that is triggered by agent.exe running – the_coder_in_me Nov 17 '17 at 22:43
  • Which command above did you run that is ending with the window closing too soon? What happens when you run agent.exe from the command line, independent of PowerShell? Does it immediately return to the command prompt? – Scott Kearney Nov 17 '17 at 22:57
  • When I run agent.exe from command line .. it pops up a small document in the cmd itself listing all the execution modes and command line parameters I can add... It does the same when I go inside the folder and run agent.exe from powershell.. Don't know the reason why its reacting when I use an external script to run the same agent.exe file – the_coder_in_me Nov 17 '17 at 23:13
0

Add this at the end of your powershell script:
It asks user to press any key and waits until user presses a key.

Write-Host "Press any key to continue ...".
$x = $host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
Syed.
  • 71
  • 1
  • 8