PowerShell use the Jint engine to perform JavaScript functions in PowerShell _powershell

Source: Internet
Author: User

This shows how to use PowerShell to hand a section of JavaScript function strings to the Jint engine for execution.

Executing JavaScript functions

. NET version of JavaScript interpreter

You can get Jint code from git, or you can download Jint assemblies from NuGet.

Jint is a. Net-oriented JavaScript interpreter. Jint does not compile JavaScript into. NET bytecode, so it works well for scripts that are small and run faster, or scripts that run on different platforms.

PowerShell Call

Get the DLL. Use the Add-type command directly from the-path parameter:

function Invoke-jsadd ($a, $b) {
Add-type–path "C:\jint\Jint.dll"

$JavaScript = "
function Add (A, b) {
return a + B;
}
"
$add = (New-object jint.engine).
Execute ($JavaScript).
GetValue ("Add")

$add. Invoke ($a, $b). ToString ()
}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.