3

Suppose I have a Windows commandline application (abc.exe) in: C:\test folder. I've put my powershell script file in the same location too.

by using this command I set the current location to the location where my script is launched from:

Set-Location $PSScriptRoot

I need to run abc.exe from within my script so that by pressing Control+C in the execution window of my script, it terminates abc.exe too.

If I use this syntax: C:\test\abc.exe in my script, everything is as what I want. but the problem is that I don't want to hard code the location of abc.exe in my script since user may change it.(note: abc.exe will always be in the same location as my script)

If I just use: abc.exe I will get:

& : The term 'abc.exe' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of 
the name, or if a path was included, verify that the path is correct and try again.

What should I do?

Update: In windows Batch scripting, pressing Control+C in such situation will easily terminates both the execution of script and commandline application

wiki
  • 1,877
  • 2
  • 31
  • 47

1 Answers1

0

Did your try this ...

Start-Process -PSPath "C:\test\abc.exe" -WorkingDirectory "C:\test" -NoNewWindow

Second suggestion:

Start-Process -PSPath "C:\test\abc.exe" -WorkingDirectory "C:\test" -NoNewWindow -Wait
Buxmaniak
  • 460
  • 2
  • 4
  • I want to have the results and interactions of abc.exe from within my script (like in batch scripts) not opening a completely separate window for running abc.exe – wiki Dec 11 '15 at 16:09
  • See second suggestion at Answer. – Buxmaniak Dec 12 '15 at 11:00