如何从 powershell 在另一个应用程序窗口中运行交互式命令 [英] How to run interactive commands in another application window from powershell
问题描述
我有另一个命令行程序,我从我的 powershell 脚本中调用它,并希望在从 powershell 打开后在该窗口中运行一些交互式命令.
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.
换句话说 - 我做了一个 Invoke-Item $link_to_app
,它打开了该应用程序的交互式命令行,现在我想从 powershell 脚本中使用应用程序特定的命令.
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.
例如app.exe -help
调用app.exe
的帮助命令.
e.g. app.exe -help
to invoke the help command of the app.exe
.
任何指针都会有所帮助.谢谢!
Any pointers would help. Thanks!
推荐答案
试试这个:
$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
根据您的扩展说明,您似乎想要在同一命令提示符下运行 2 个命令.这是可能的,但是,我不确定它是否适用于您的场景.例如:
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:回声你好!"
test2.bat: echo "goodbye!"
test2.bat: echo "goodbye!"
$batchTest = "test1.bat && test2.bat"
cmd /c $batchTest
输出:
D:\Test>echo "hello!"
"hello!"
D:\Test>echo "goodbye!"
"goodbye!"
希望这会有所帮助.
这篇关于如何从 powershell 在另一个应用程序窗口中运行交互式命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!