New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rpc: Input-from-stdin mode for bitcoin-cli #7550

Merged
merged 2 commits into from Feb 24, 2016

Conversation

Projects
None yet
3 participants
@laanwj
Member

laanwj commented Feb 17, 2016

Implements #7442 by adding an option -stdin which reads additional arguments from standard in, one per line.

For example

$ echo -e "mysecretcode\n120" | src/bitcoin-cli -stdin walletpassphrase
$ echo -e "walletpassphrase\nmysecretcode\n120" | src/bitcoin-cli -stdin
$ src/bitcoin-cli -stdin walletpassphrase
mysecretcode
120
^D

This is the simplest implementation and avoids escaping issues by using newline as separator instead of space, I first had another implementation: laanwj@1f73b8e that reuses parseCommandLine from the GUI debug console, but I think this is more useful in practice as most use of cli is probably script-driven.

@laanwj laanwj added the RPC/REST/ZMQ label Feb 17, 2016

@paveljanik

This comment has been minimized.

Show comment
Hide comment
@paveljanik

paveljanik Feb 17, 2016

Contributor

Brilliant idea!

ACK laanwj@c97198d

pavel$ echo -e "getblockhash\n0" | bitcoin-7550/src/bitcoin-cli -stdin
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
pavel$ 
Contributor

paveljanik commented Feb 17, 2016

Brilliant idea!

ACK laanwj@c97198d

pavel$ echo -e "getblockhash\n0" | bitcoin-7550/src/bitcoin-cli -stdin
000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f
pavel$ 

@laanwj laanwj added the Feature label Feb 17, 2016

@jonasschnelli

This comment has been minimized.

Show comment
Hide comment
@jonasschnelli

jonasschnelli Feb 18, 2016

Member

Nice!
Concept ACK. Plans to test this soon.

Member

jonasschnelli commented Feb 18, 2016

Nice!
Concept ACK. Plans to test this soon.

if (GetBoolArg("-stdin", false)) {
// Read one arg per line from stdin and append
std::string line;
while (std::getline(std::cin,line))

This comment has been minimized.

@jonasschnelli

jonasschnelli Feb 19, 2016

Member

what about adding a magic work as ^D alternative? Something like "end" or "quit"?

@jonasschnelli

jonasschnelli Feb 19, 2016

Member

what about adding a magic work as ^D alternative? Something like "end" or "quit"?

This comment has been minimized.

@laanwj

laanwj Feb 19, 2016

Member

I've thought about that. The problem is that anything could be a valid argument. I've chosen the line-per-argument, until EOL to avoid that kind of escaping issues.
It's easy for scripting but yes for a user interface it's not very friendly.

master...laanwj:2016_02_cli_stdin is better in that regard, but what makes it an easier user interface is annoying/dangerous for scripting (as you'd have to quote ' "" etc to prevent one argument from spilling into the next)

@laanwj

laanwj Feb 19, 2016

Member

I've thought about that. The problem is that anything could be a valid argument. I've chosen the line-per-argument, until EOL to avoid that kind of escaping issues.
It's easy for scripting but yes for a user interface it's not very friendly.

master...laanwj:2016_02_cli_stdin is better in that regard, but what makes it an easier user interface is annoying/dangerous for scripting (as you'd have to quote ' "" etc to prevent one argument from spilling into the next)

This comment has been minimized.

@jonasschnelli

jonasschnelli Feb 22, 2016

Member

Maybe adding a little ">>>" prompt and or giving a one-line-help-instruction when using -stdin (something like "enter command, arguments and use Ctrl-D to quit/execute")?

Allow quitting over "quit()" and if "exit" or "quit" has been typed, show little help line?
Though, a simple one-line-help-message would probably do the job.

Python example:

:~ jonasschnelli$ python
Python 2.7.10 (default, Sep 23 2015, 04:34:14) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> quit
Use quit() or Ctrl-D (i.e. EOF) to exit
@jonasschnelli

jonasschnelli Feb 22, 2016

Member

Maybe adding a little ">>>" prompt and or giving a one-line-help-instruction when using -stdin (something like "enter command, arguments and use Ctrl-D to quit/execute")?

Allow quitting over "quit()" and if "exit" or "quit" has been typed, show little help line?
Though, a simple one-line-help-message would probably do the job.

Python example:

:~ jonasschnelli$ python
Python 2.7.10 (default, Sep 23 2015, 04:34:14) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.72)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> quit
Use quit() or Ctrl-D (i.e. EOF) to exit

This comment has been minimized.

@laanwj

laanwj Feb 24, 2016

Member

That would be awesome for an "interactive mode" (see #3122), but -stdin is explicitly not meant to be that, it's just to have a way to input data (say, from scripts) that isn't exposed on the command line. Printing more text will make it harder to parse the output.

@laanwj

laanwj Feb 24, 2016

Member

That would be awesome for an "interactive mode" (see #3122), but -stdin is explicitly not meant to be that, it's just to have a way to input data (say, from scripts) that isn't exposed on the command line. Printing more text will make it harder to parse the output.

This comment has been minimized.

@jonasschnelli

jonasschnelli Feb 24, 2016

Member

Agree. Was nitpick territory anyway (does not affect my tested ACK I already gave).

@jonasschnelli

jonasschnelli Feb 24, 2016

Member

Agree. Was nitpick territory anyway (does not affect my tested ACK I already gave).

This comment has been minimized.

@laanwj

laanwj Feb 24, 2016

Member

Right, for now, I've added a EOF/Ctrl-D mention to the -help message at least.

@laanwj

laanwj Feb 24, 2016

Member

Right, for now, I've added a EOF/Ctrl-D mention to the -help message at least.

@jonasschnelli

This comment has been minimized.

Show comment
Hide comment
@jonasschnelli

jonasschnelli Feb 19, 2016

Member

Tested ACK c97198db769954c4ad2b57eaf7e5335578badc00

Post-merge actions: add to the docs/release notes, maybe add a little test script (though, not sure if we have a test entry point for bitcoin-cli at all).

Member

jonasschnelli commented Feb 19, 2016

Tested ACK c97198db769954c4ad2b57eaf7e5335578badc00

Post-merge actions: add to the docs/release notes, maybe add a little test script (though, not sure if we have a test entry point for bitcoin-cli at all).

rpc: Input-from-stdin mode for bitcoin-cli
Implements #7442 by adding an option `-stdin` which reads
additional arguments from stdin, one per line.

For example

```bash
echo -e "mysecretcode\n120" | src/bitcoin-cli -stdin walletpassphrase
echo -e "walletpassphrase\nmysecretcode\n120" | src/bitcoin-cli -stdin
```
@jonasschnelli

This comment has been minimized.

Show comment
Hide comment
@jonasschnelli
Member

jonasschnelli commented Feb 24, 2016

Re-ACK 92bcca3

@laanwj laanwj merged commit f22f14c into bitcoin:master Feb 24, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

laanwj added a commit that referenced this pull request Feb 24, 2016

Merge #7550: rpc: Input-from-stdin mode for bitcoin-cli
f22f14c doc: mention bitcoin-cli -stdin in release notes (Wladimir J. van der Laan)
92bcca3 rpc: Input-from-stdin mode for bitcoin-cli (Wladimir J. van der Laan)

luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Jun 28, 2016

laanwj added a commit that referenced this pull request Sep 6, 2017

Merge #11125: Add bitcoin-cli -stdin and -stdinrpcpass functional tests
29e1dfb [test] Add bitcoin-cli -stdin and -stdinrpcpass functional tests (João Barbosa)
ce379b4 [test] Replace check_output with low level version (João Barbosa)
232e3e8 [test] Add assert_raises_process_error to assert process errors (João Barbosa)
5c18a84 [test] Add support for custom arguments to TestNodeCLI (João Barbosa)
e127494 [test] Improve assert_raises_jsonrpc docstring (João Barbosa)
7696841 Fix style in -stdin and -stdinrpcpass handling (João Barbosa)

Pull request description:

  This patch adds tests for `bitcoin-cli` options `-stdin` (#7550) and `-stdinrpcpass` #10997.

Tree-SHA512: fd8133f44876f2b5b41dfd3762b1988598f6b7bf13fb2385ad95876825d9c0b2b896ce4ea6eeb21012158e1f276907f155d37bb967198b609d2d3dddbfa334c1

@codablock codablock referenced this pull request Oct 20, 2017

Closed

[WIP] Update build system to Bitcoin 0.13.2 #1692

22 of 24 tasks complete

codablock added a commit to codablock/dash that referenced this pull request Dec 9, 2017

Merge #7550: rpc: Input-from-stdin mode for bitcoin-cli
f22f14c doc: mention bitcoin-cli -stdin in release notes (Wladimir J. van der Laan)
92bcca3 rpc: Input-from-stdin mode for bitcoin-cli (Wladimir J. van der Laan)

codablock added a commit to codablock/dash that referenced this pull request Dec 9, 2017

Merge #7550: rpc: Input-from-stdin mode for bitcoin-cli
f22f14c doc: mention bitcoin-cli -stdin in release notes (Wladimir J. van der Laan)
92bcca3 rpc: Input-from-stdin mode for bitcoin-cli (Wladimir J. van der Laan)

@str4d str4d referenced this pull request Mar 14, 2018

Merged

CLI binary improvements #3086

zkbot added a commit to zcash/zcash that referenced this pull request Apr 13, 2018

Auto merge of #3086 - str4d:cli-binary-improvements-1, r=str4d
CLI binary improvements

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#5936
- bitcoin/bitcoin#7550
- bitcoin/bitcoin#7989
- bitcoin/bitcoin#7957
- bitcoin/bitcoin#9067
- bitcoin/bitcoin#9220

Excludes any changes that affected the QT code.

zkbot added a commit to zcash/zcash that referenced this pull request Apr 13, 2018

Auto merge of #3086 - str4d:cli-binary-improvements-1, r=str4d
CLI binary improvements

Cherry-picked from the following upstream PRs:

- bitcoin/bitcoin#5936
- bitcoin/bitcoin#7550
- bitcoin/bitcoin#7989
- bitcoin/bitcoin#7957
- bitcoin/bitcoin#9067
- bitcoin/bitcoin#9220

Excludes any changes that affected the QT code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment