Last active
July 20, 2017 16:50
-
-
Save cat2151/95e39bd148c19ea1a45d02b5bf75914c to your computer and use it in GitHub Desktop.
batファイル内のPowerShell内のJavaScriptプログラムを動かす
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@%windir%\SysWOW64\cmd.exe /C powershell -NoProfile -ExecutionPolicy Unrestricted "$s=[scriptblock]::create((gc \"%~f0\"|?{$_.readcount -gt 1})-join\"`n\");&$s" %*&goto:eof | |
# http://qiita.com/cd01/items/82829ba0ec0f59e1b04d | |
# http://blog.livedoor.jp/morituri/archives/53997724.html | |
Param($argBat) | |
$objjs = New-Object -comobject ScriptControl | |
$objjs.Language = "Javascript" | |
$src = @' | |
function helloFunc(arg) { | |
msg = "hello " + arg + " world"; | |
print(msg); | |
return msg; | |
} | |
var log = ""; | |
function print(v) { | |
log += v; | |
} | |
function readLog() { | |
return log; | |
} | |
'@ | |
$objjs.Eval($src) | |
$helloResult = $objjs.CodeObject.helloFunc($argBat) | |
Write-Output -InputObject $helloResult | |
Write-Output -InputObject $objjs.CodeObject.readLog() | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
特に根拠はないが、
batファイル内のPowerShell内のJScript.NET(≒JavaScript)プログラムを動かす
のほうがよさそう。あちらのほうが将来性、安定性、機能性などの面で有利そうに見受けられる。