How to run interactive commands in another application window from powershell

user1575430 picture user1575430 · Jun 20, 2013 · Viewed 12.5k times · Source

I have another command line program which I invoke from my powershell script and would like to run some interactive commands in that window once it is opened from power shell.

In other words - I do a Invoke-Item $link_to_app which opens up the interactive command line for that application and now I would like to use the application specific commands from within powershell scripts.

e.g. app.exe -help to invoke the help command of the app.exe.

Any pointers would help. Thanks!

Answer

Kyle Muir picture Kyle Muir · Jun 20, 2013

Try this:

$app = 'app.exe -help'
Invoke-Expression $app

Tested with this and it worked as expected:

$pingTest = 'ping -n 8 127.0.0.1'
Invoke-Expression $pingTest

From your expanded explanation you appear to want to run 2 commands within the same command prompt. This is possible, however, I'm not sure it will work in your scenario. For example:

test1.bat: echo "hello!"

test2.bat: echo "goodbye!"

$batchTest = "test1.bat && test2.bat"
cmd /c $batchTest 

output:

D:\Test>echo "hello!"
"hello!"

D:\Test>echo "goodbye!"
"goodbye!"

Hope this helps.