# Begin ----------------------------------------------------------------
Param(
[String]$Arguments
)
# Function CallScript
function CallScript {
Param(
[String]$Interpreter,
[String]$ScriptFile,
[String]$Arguments
)
[System.Diagnostics.ProcessStartInfo]$startInfo = `
[System.Diagnostics.ProcessStartInfo]::new();
$startInfo.FileName = $Interpreter;
$startInfo.Arguments = "$($ScriptFile) $($Arguments)";
$startInfo.UseShellExecute = $False;
$startInfo.CreateNoWindow = $True;
$startInfo.RedirectStandardOutput = $True;
$startInfo.RedirectStandardError = $True;
[System.Diagnostics.Process]$Proc = `
[System.Diagnostics.Process]::new();
$Proc.StartInfo = $startInfo;
if ($Proc.Start() -eq $False) {
Return;
}
[System.IO.StreamReader]$stdOut = $Proc.StandardOutput;
[System.IO.StreamReader]$stdErr = $Proc.StandardError;
if (($stdOut -eq $null) -or ($stdErr -eq $null)) {
Return;
}
$Result = $stdOut.ReadToEnd();
if ($Result.Length -eq 0) {
Return $stdErr.ReadToEnd();
} Else {
Return $Result;
}
}
# Sub Main
function Main {
"PowerShell Version: " + $PSVersionTable.PSVersion.Major + "." +
$PSVersionTable.PSVersion.Minor + [System.Environment]::NewLine;
if ([String]::IsNullOrEmpty($($Arguments))) {
$Arguments = """Hello World"""
}
$Result = CallScript `
-Interpreter "C:\Program Files\Python\python.exe" `
-ScriptFile "C:\Dummy\CallPythonFromPS.py" `
-Arguments $Arguments;
$Result;
$Result = CallScript `
-Interpreter "C:\Program Files\AutoIt\AutoIt3_x64.exe" `
-ScriptFile "C:\Dummy\CallAutoItFromPS.au3" `
-Arguments $Arguments;
$Result;
}
# Main
Main;
[Void][Console]::WriteLine("`nPress key...");
[Void][Console]::ReadKey("NoEcho,IncludeKeyDown");
# End ------------------------------------------------------------------