如何在Powershell中退出要求用户输入的进程?

时间:2017-12-01 16:05:15

标签: powershell powershell-v2.0 powershell-v3.0 powershell-v4.0 powershell-remoting

我想调用命令行进程,假设进程接受用户输入,例如“按Enter键退出”。

如何调用某种进程并从该进程获取返回值?

上面的代码在Powershell中崩溃了吗?

function InvokeProcess 
{
param (
        [parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]$ExeName,
        [parameter(Mandatory=$false)]
        [ValidateNotNullOrEmpty()]$Arguments
    )
    try 
    {
        [string] $ExecutablePath = $Path + $ExeName
        $FullPath = [string] $ExecutablePath + $Arguments 
        $result = & $FullPath
    }
    catch 
    {
        $Msg = "Exception: $error[0]"
       WriteLog $Msg "Error"
    }
}

1 个答案:

答案 0 :(得分:0)

$ result =& $ ExecutablePath $ arg1 $ arg2