Answer the question
In order to leave comments, you need to log in
How to run console application in powershell?
Good afternoon.
It is necessary to execute a console application and get the output into a variable with the array type.
Found the launch of the application through an object:
$pinfo = New-Object System.Diagnostics.ProcessStartInfo
$pinfo.FileName = "ping"
$pinfo.Arguments = "8.8.8.8 -n 1"
$pinfo.RedirectStandardError = $true
$pinfo.RedirectStandardOutput = $true
$pinfo.UseShellExecute = $false
$pinfo.CreateNoWindow = $true
$p = New-Object System.Diagnostics.Process
$p.StartInfo = $pinfo
$p.Start() | Out-Null
$p.WaitForExit()
$output = $p.StandardOutput.ReadToEnd()
$output += $p.StandardError.ReadToEnd()
$output
& ping 8.8.8.8 -n 1
$param = '8.8.8.8'
$param2 = '-n'
$param3 = '1'
& "ping" $param $param2 $param3
$param = '8.8.8.8 -n 1'
& "ping" $param
Answer the question
In order to leave comments, you need to log in
and the console application is exactly ping?
what is the end goal of this script?
if you check the availability of hosts, that is, test-connection and test-netconnection. if they are not in power 4, then upgrade to 5.1.
I came to the next view
And then parsing the output file. It turned out more predictable ... In terms of time - comparable.
In your example, you could try FileName="cmd" Arguments= "ping with options". StdErr and StdOut are best separated into different variables.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question