python与exe程序交互_nsPython是NSIS与Python脚本进行交互编程的插件

/*

nsPython是NSIS与Python脚本进行交互编程的插件

nsPython支持命令eval,exec和execFile来与Python脚本进行交互.使用的时候要注意平台,如64位系统之类的差异.

*/

!AddPluginDir "../Plugins"

Name "Test-nspython"

OutFile "Test-nspython.exe"

ShowInstDetails show

ComponentText "select tests"

ReserveFile "python27.dll"

ReserveFile "test.py"

;Page components

;Page instfiles

Function .onInit

;Extract Install Options files

;$PLUGINSDIR will automatically be removed when the installer closes

InitPluginsDir

File "/oname=$PLUGINSDIRpython27.dll" "python27.dll"

File "/oname=$PLUGINSDIRtest.py" "test.py"

FunctionEnd

Function .onGUIEnd

nsPython::Finalize

FunctionEnd

Section "Test eval"

nsPython::eval "3+2"

Pop $0

DetailPrint "Result: $0"

nsPython::eval "make an error"

Pop $0

DetailPrint "Result: $0"

SectionEnd

Section "Test exec logprint"

nsPython::exec "import nsis;a=3+2;nsis.log('embedded messy: a=%r' % a)"

Pop $0

DetailPrint "Result: $0"

nsPython::exec "make an error"

Pop $0

DetailPrint "Result: $0"

SectionEnd

Section "Test exec msgbox"

nsPython::exec "import nsis;a=3+2;nsis.messagebox('embedded messy: a=%r' % a);"

Pop $0

DetailPrint "Result: $0"

nsPython::exec "import nsis;nsis.messagebox('with custom title', 'this was me');"

Pop $0

DetailPrint "Result: $0"

SectionEnd

Section "Test exec file"

DetailPrint "nsPython::execFile $PLUGINSDIRtest.py"

nsPython::execFile "$PLUGINSDIRtest.py"

Pop $0

DetailPrint "Result: $0"

SectionEnd

Section "Test exec help and vars"

nsPython::exec "import nsis;[nsis.log(nsis.__dict__[x].__doc__) for x in ('log', 'messagebox', 'getvar', 'setvar')]"

Pop $0

;indentation is a bit tricy, NSIS removes leading spaces from continued lines

;thus the indentation ha to be done through a variable substitution.

;also be careful as the maximum NSIS string length is 1024 bytes.

StrCpy $1 " "

nsPython::exec "import nsis$n

for x in ('$$0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'R0', 'R1', 'R2', 'R3', 'R4', 'R5', 'R6', 'R7', 'R8', 'R9', 'CMDLINE', 'INSTDIR', 'OUTDIR', 'EXEDIR', 'LANGUAGE'):$n

$1 nsis.log('%s = %r' % (x, nsis.getvar(x)))$n"

Pop $0

StrCpy $0 "hello world"

DetailPrint "value of $$1: $1"

nsPython::exec "import nsis;nsis.setvar('1', 'yup')"

Pop $0

DetailPrint "new value of $$1: $1"

SectionEnd

Section "Test exec handles"

nsPython::exec "import nsis;nsis.log('parent: %r' % nsis.getParent())"

Pop $0

SectionEnd

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值