Powershellbatch 混合没有临时文件

这是 stackoverflow 的用户 rojo提出的方法 ,它也可以处理命令行参数:

<# : batch portion
@echo off & setlocal

(for %%I in ("%~f0";%*) do @echo(%%~I) | ^
powershell -noprofile "$argv = $input | ?{$_}; iex (${%~f0} | out-string)"

goto :EOF
: end batch / begin powershell #>

"Result:"
$argv | %{ "`$argv[{0}]: $_" -f $i++ }

像这样叫:

psbatch.bat arg1“这是 arg2”arg3

将产生:

Result:
$argv[0]: C:\Users\rojo\Desktop\test.bat
$argv[1]: arg1
$argv[2]: This is arg2
$argv[3]: arg3