aboutsummaryrefslogtreecommitdiffstats
path: root/cmd
diff options
context:
space:
mode:
Diffstat (limited to 'cmd')
-rw-r--r--cmd/geth/js.go19
-rw-r--r--cmd/geth/main.go17
-rw-r--r--cmd/utils/flags.go4
3 files changed, 36 insertions, 4 deletions
diff --git a/cmd/geth/js.go b/cmd/geth/js.go
index 6e4e3e0c1..761943b63 100644
--- a/cmd/geth/js.go
+++ b/cmd/geth/js.go
@@ -220,6 +220,25 @@ func (self *jsre) loadAutoCompletion() {
}
}
+func (self *jsre) batch(statement string) {
+ val, err := self.re.Run(statement)
+
+ if err != nil {
+ fmt.Printf("error: %v", err)
+ } else if val.IsDefined() && val.IsObject() {
+ obj, _ := self.re.Get("ret_result")
+ fmt.Printf("%v", obj)
+ } else if val.IsDefined() {
+ fmt.Printf("%v", val)
+ }
+
+ if self.atexit != nil {
+ self.atexit()
+ }
+
+ self.re.Stop(false)
+}
+
// show summary of current geth instance
func (self *jsre) welcome() {
self.re.Eval(`console.log('instance: ' + web3.version.client);`)
diff --git a/cmd/geth/main.go b/cmd/geth/main.go
index f1e8ace3d..e5c3614fc 100644
--- a/cmd/geth/main.go
+++ b/cmd/geth/main.go
@@ -255,6 +255,7 @@ JavaScript API. See https://github.com/ethereum/go-ethereum/wiki/Javascipt-Conso
utils.IPCDisabledFlag,
utils.IPCApiFlag,
utils.IPCPathFlag,
+ utils.ExecFlag,
utils.WhisperEnabledFlag,
utils.VMDebugFlag,
utils.ProtocolVersionFlag,
@@ -337,8 +338,12 @@ func attach(ctx *cli.Context) {
true,
nil)
- repl.welcome()
- repl.interactive()
+ if ctx.GlobalString(utils.ExecFlag.Name) != "" {
+ repl.batch(ctx.GlobalString(utils.ExecFlag.Name))
+ } else {
+ repl.welcome()
+ repl.interactive()
+ }
}
func console(ctx *cli.Context) {
@@ -368,8 +373,12 @@ func console(ctx *cli.Context) {
nil,
)
- repl.welcome()
- repl.interactive()
+ if ctx.GlobalString(utils.ExecFlag.Name) != "" {
+ repl.batch(ctx.GlobalString(utils.ExecFlag.Name))
+ } else {
+ repl.welcome()
+ repl.interactive()
+ }
ethereum.Stop()
ethereum.WaitForShutdown()
diff --git a/cmd/utils/flags.go b/cmd/utils/flags.go
index 092bc5511..a9d449d1f 100644
--- a/cmd/utils/flags.go
+++ b/cmd/utils/flags.go
@@ -227,6 +227,10 @@ var (
Usage: "Filename for IPC socket/pipe",
Value: DirectoryString{common.DefaultIpcPath()},
}
+ ExecFlag = cli.StringFlag{
+ Name: "exec",
+ Usage: "Execute javascript statement (only in combination with console/attach)",
+ }
// Network Settings
MaxPeersFlag = cli.IntFlag{
Name: "maxpeers",