-2

I want to use commands from the hd-wallet-derive command tool in my website.

For example I run this in Ubuntu terminal and it works fine:

$ ./hd-wallet-derive.php -g --key=xprv9tyUQV64JT5qs3RSTJkXCWKMyUgoQp7F3hA1xzG6ZGu6u6Q9VMNjGr67Lctvy5P8oyaYAL9CAWrUE9i6GoNMKUga5biW6Hx4tws2six3b9c --path=m/1 --cols=all --includeroot --numderive=3

But how can I use this code in my PHP file and get output?

For example if I click on a button in my PHP page, the below command run?

  • please specify what *works fine* means. Does this include providing some output, or you need to just run those commands? – YakovL Nov 25 '18 at 09:25
  • When I use the command that I wrote upper in ubuntu terminal, It's gives me output. so how can I receive same output in .php file? how can I use -g in .php file and get the output? – FreeJoyMan Nov 25 '18 at 15:00
  • You can use the `exec` function to run the terminal command from your php code. http://php.net/manual/en/function.exec.php – Valerian Pereira Nov 25 '18 at 15:57
  • Links in the comments to https://stackoverflow.com/q/6805963/3995261 may be helpful (the short answer seems to be – it's not possible via `include`). The script you linked uses `getopt` so one question essentially is – how can you pass options to the script that uses `getopt`. May be the approach Valerian has suggested is the only option – YakovL Nov 25 '18 at 18:23
  • thank u guys, when I create a .php file and copy this code in it ' – FreeJoyMan Nov 26 '18 at 09:33

2 Answers2

0

hd-wallet-derive is sending usage info to stderr, not stdout. To capture that, you could run the command as eg: ./hd-wallet-derive -g 2>&1

More to your question though, there is an option --outfile= to write report output to a given file. In a web app, you should specify a unique filename for the user. Further, you can specify what type of report output you want using the --format flag.

Usage info is here: https://github.com/dan-da/hd-wallet-derive#usage

danda
  • 485
  • 4
  • 13
  • how can I use this library to get a PHP response like an array. I want to use this as a standard PHP library. Can you guide us on how we can achieve this? – JGCW May 03 '21 at 18:06
0

The code which you searched --format=jsonpretty and --outfile="logs/shell_result.txt"

    $cmd = 'php hd2/hd-wallet-derive.php --mnemonic="edge defense waste choose enrich upon flee junk siren film clown finish luggage leader kid quick brick print evidence swap drill paddle truly occur" ';
    $cmd.= '-g --path=m/44/60/0 --cols=all --includeroot --numderive=3 ';
    $cmd.= '--format=jsonpretty ';
    $cmd.= '--outfile="logs/shell_result.txt"';

    shell_exec($cmd);
    print_r(json_decode(file_get_contents('logs/shell_result.txt'), true));
Alper AKPINAR
  • 71
  • 3
  • 10