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

9
  • 1
    Checkout: stackoverflow.com/questions/4724290/…. Also note, use ".\abc.exe" to reference the command in the current directory. Commented Dec 10, 2015 at 18:26
  • I read that but couldn't figure out what to do Commented Dec 10, 2015 at 18:32
  • What part couldn't you figure out? Commented Dec 10, 2015 at 18:33
  • The exact code that I should use Commented Dec 10, 2015 at 18:34
  • & $PSScriptRoot\abc.exe Commented Dec 10, 2015 at 18:40

1 Answer 1

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
Sign up to request clarification or add additional context in comments.

2 Comments

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
See second suggestion at Answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.