[英]How to ignore pause - press any key - in Powershell while executing file
Using Powershell I am starting some executable using invoke-expression
like: 使用Powershell我正在使用
invoke-expression
来启动一些可执行文件,例如:
Invoke-Expression "c:\exec.exe"
now my problem is this exec is showing something like "pause and press any key to continue". 现在我的问题是该执行人员显示的是“暂停并按任意键继续”之类的内容。
I tried: 我试过了:
Function Run-Tool
{
Invoke-Expression "c:\exec.exe"
$host.UI.RawUI.ReadKey("NoEcho,IncludeKeyDown")
}
But no luck. 但是没有运气。
My question is can I ignore that message some sort of suppression or is there a way to monitor output and simulate pressing any key? 我的问题是我可以忽略该消息吗?还是可以监视输出并模拟按任意键?
If exec.exe
is a regular console app expecting a newline a la: 如果
exec.exe
是常规控制台应用程序,需要换行符:
Console.Write("Press any key to exit...");
Console.ReadLine();
Then you could just pipe a newline to it: 然后,您可以通过管道将换行符发送给它:
"`n" |& C:\exec.exe
you can redirect the enter key from powershell to the program by using processstartinfo and process : 您可以使用processstartinfo和process将Enter键从powershell重定向到程序:
$psi = New-Object System.Diagnostics.ProcessStartInfo;
$psi.FileName = "C:\yourexe.exe";
$psi.UseShellExecute = $false;
$psi.RedirectStandardInput = $true;
$p = [System.Diagnostics.Process]::Start($psi);
Start-Sleep -s 2 # if your exe needs time to give output
$p.StandardInput.WriteLine("`n");
Using $host.UI.RawUI.ReadKey
will not do what you are after - the ReadKey
function waits for input and returns info on the key that was pressed. 使用
$host.UI.RawUI.ReadKey
不会执行您要执行的操作ReadKey
函数等待输入并返回有关所按下键的信息。 So instead of sending input, it is waiting for input. 因此,它不等待发送输入,而是在等待输入。
This answer is related to your situation - perhaps you can use the method suggested there. 这个答案与您的情况有关-也许您可以使用此处建议的方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.