我目前正在编写一个简单的expect
脚本来打开以太坊geth console
并执行以下命令:
#!/usr/bin/expect
spawn /usr/bin/geth --testnet console
expect ">"
send "personal.unlockAccount('0xdc85a8429998bd4eef79307e556f70bb70d8caf1','X');\r"
expect "true"
expect ">"
send "var mortalContract=web3.eth.contract([{constant:!1,inputs:[],name:'kill',outputs:[],type:'function'},{constant:!1,inputs:[],name:'cashOut',outputs:[],type:'function'},{inputs:[],type:'constructor'}]),mortal=mortalContract['new']({from:'0xdc85a8429998bd4eef79307e556f70bb70d8caf1',data:'60606040525b33600060006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908302179055505b61016e8061003f6000396000f360606040526000357c01000000000000000000000000000000000000000000000000000000009004806341c0e1b514610044578063793cd71e1461005357610042565b005b6100516004805050610062565b005b61006060048050506100f6565b005b600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614156100f357600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16ff5b5b565b60003073ffffffffffffffffffffffffffffffffffffffff16319050600060009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16600060028304604051809050600060405180830381858888f19350505050505b5056',gas:47e5},function(f,t){console.log(f,t),'undefined'!=typeof t.address&&console.log('Contract mined! address: '+t.address+' transactionHash: '+t.transactionHash)});\r"
expect "undefined"
expect ">"
send "exit\r"
expect eof
编译器在第7行(以var mortalContract
开头的那个)存在问题。我四处搜索,发现双引号内的双引号会打扰期望所以我将双内引号更改为单引号但它仍然无法正常工作并返回以下错误:
extra characters after close-brace
while executing
"send "var mortalContract=web3.eth.contract([{constant:!1,inputs:[],name:'kill',outputs:[],type:'function'},"
(file "expectScript.js" line 7)
答案 0 :(得分:1)
需要在每个右括号后添加空格}
答案 1 :(得分:1)
方括号是Tcl中的特殊语法。它们就像shell中的反引号:执行包含在其中的命令并替换为结果。与shell一样,双引号允许命令替换。我会使用Tcl的非插值引号,它们是花括号:
send {var mortalContract=web3.eth.contract([{constant:... '+t.transactionHash)});}
# ...^...........................................................................^
send "\r"