humanemulator.net — справка. Продукт, демо и покупка — на хуманэмулятор.рф | Демо | Купить | API | лог изменений
К объекту app

run_powershell_script

run_powershell_script($path); - выполнить PowerShell скрипт - файл на том компютере, где работает хуман эмулятор. доступна с 7.0.63.

Функция на вход принимает параметры:

  • $path – путь к файлу скрипта

    После отработки функция возвращает результат своей работы в скрипт :
  • текст – результат выполненяи скрипта


    Пример использования
    <?php
    // Scenario: Execute PowerShell scripts with and without parameters
    $xhe_host = "127.0.0.1:5006";
    if (!isset($path)){
        // Path to the init.php file for connecting to the XHE API
        $path = "../../../Templates/init.php";
        // Including init.php grants access to all classes and functionality for working with the XHE API
        require($path);
    }
    
    // beginning
    echo "\n<font color=blue>app->" . basename (__FILE__) . "</font>\n";
    
    // Example 1
    echo "\n\n1. Execute non-existent script\n";
    $scriptPath = "any.ps";
    $runResult = WINDOW::$app->run_powershell_script($scriptPath);
    if ($runResult) {
    	echo "PowerShell script executed successfully\n";
    } else {
    	echo "PowerShell script execution failed as expected (non-existent script)\n";
    }
    
    // Example 2
    echo "\n\n2. Execute existing script\n";
    $scriptPath = "test/powershell_script.ps";
    $runResult = WINDOW::$app->run_powershell_script($scriptPath);
    if ($runResult) {
    	echo "PowerShell script executed successfully\n";
    } else {
    	echo "PowerShell script execution failed\n";
    }
    
    // Example 3
    echo "\n\n3. Execute script with parameters\n";
    $scriptPath = "test/params.ps1";
    $parameters = array("parameter1", "parameter2");
    $runResult = WINDOW::$app->run_powershell_script($scriptPath, $parameters);
    if ($runResult) {
    	echo "PowerShell script with parameters executed successfully\n";
    } else {
    	echo "PowerShell script with parameters execution failed\n";
    }
    sleep(1);
    
    // end
    echo "\n";
    
    // Quit the application
    WINDOW::$app->quit();
    ?>
    # Additional paths
    import sys
    sys.path.insert(0, '../../../Templates PY/')
    
    xhe_host = "127.0.0.1:3035"
    from xweb_human_emulator import *
    
    # начало
    echo("<hr><font color=blue>app.xxxxxxxxx</font><hr>")
    
    # 1 
    echo("1. Выполним несуществующий скрипт : ")
    echo(app.run_powershell_script("any.ps"),"<br>")
    
    # 2 
    echo("2. Выполним скрипт  : ")
    echo(app.run_powershell_script("test/powershell_script.ps"),"<br>")
    
    # конец
    echo("<hr><br>")
    
    # Quit
    app.quit()
    #region using
    
    using System;
    using System.Diagnostics;
    using System.Collections.Generic;
    using System.Linq;
    using System.IO;
    using System.Text;
    using System.Threading;
    
    using XHE;
    using XHE.XHE_DOM;
    using XHE.XHE_System;
    using XHE.XHE_Window;
    using XHE.XHE_Web;
    
    #endregion
    
     class Program:XHEScript
     {
    	  static void Main(string[] args)
    	  {
    			// init XHE
    			server = "localhost:7010";
    			InitXHE();
    
    			// начало
    			echo("<hr><font color=blue>app.run_script</font><hr>");
    
    			// 1 
    			echo("1. Выполним несуществующий скрипт : ");
    			echo(app.run_powershell_script("any.ps")+"<br>");
    
    			// 2 
    			echo("2. Выполним скрипт  : ");
    			echo(app.run_powershell_script("test/powershell_script.ps")+"<br>");
    
    			// конец
    			echo("\n\n");
    
    			app.quit();            
    	  }
    }
    // подключим функциональные объекты, если еще не подключен
    xhe_host="127.0.0.1:3035";
    echo=require("../../../Templates JS/init.js");
    
    // начало
    echo("<hr><font color=blue>app.run_script</font><hr>");
    
    // 1 
    echo("1. Выполним несуществующий скрипт : ")
    echo(app.run_powershell_script("any.ps")+"<br>")
    
    // 2 
    echo("2. Выполним скрипт  : ")
    echo(app.run_powershell_script("test/powershell_script.ps")+"<br>")
    
    // конец
    echo("\n");
    
    // Quit
    app.quit();

    =============================================
    App    Объекты    DOM  System  Vision  Web  Window        
    =============================================
    если что-то непонятно или необходимо узнать или считаете что надо добавить по работе этой функции, пишите в комментарии или на наш форум
    .