Question:
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:
Try this:
1 2 3 |
$app = 'app.exe -help' Invoke-Expression $app |
Tested with this and it worked as expected:
1 2 3 |
$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!"
1 2 3 |
$batchTest = "test1.bat && test2.bat" cmd /c $batchTest |
output:
1 2 3 4 5 6 |
D:\Test>echo "hello!" "hello!" D:\Test>echo "goodbye!" "goodbye!" |
Hope this helps.