我想调用命令行进程,假设进程接受用户输入,例如“按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"
}
}
答案 0 :(得分:0)
$ result =& $ ExecutablePath $ arg1 $ arg2