mirror of
https://github.com/basicswap/basicswap.git
synced 2025-01-25 11:55:51 +00:00
Always use subprocess without shell
This commit is contained in:
parent
76c7a281bb
commit
ea347093c2
2 changed files with 21 additions and 10 deletions
|
@ -5,6 +5,7 @@
|
||||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import shlex
|
||||||
import logging
|
import logging
|
||||||
import threading
|
import threading
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -108,10 +109,11 @@ class BaseApp:
|
||||||
|
|
||||||
def calltx(self, cmd):
|
def calltx(self, cmd):
|
||||||
bindir = self.coin_clients[Coins.PART]['bindir']
|
bindir = self.coin_clients[Coins.PART]['bindir']
|
||||||
command_tx = os.path.join(bindir, cfg.PARTICL_TX)
|
args = [os.path.join(bindir, cfg.PARTICL_TX), ]
|
||||||
chainname = '' if self.chain == 'mainnet' else (' -' + self.chain)
|
if self.chain != 'mainnet':
|
||||||
args = command_tx + chainname + ' ' + cmd
|
args.append('-' + self.chain)
|
||||||
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
args += shlex.split(cmd)
|
||||||
|
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
out = p.communicate()
|
out = p.communicate()
|
||||||
if len(out[1]) > 0:
|
if len(out[1]) > 0:
|
||||||
raise ValueError('TX error ' + str(out[1]))
|
raise ValueError('TX error ' + str(out[1]))
|
||||||
|
@ -121,9 +123,12 @@ class BaseApp:
|
||||||
bindir = self.coin_clients[coin_type]['bindir']
|
bindir = self.coin_clients[coin_type]['bindir']
|
||||||
datadir = self.coin_clients[coin_type]['datadir']
|
datadir = self.coin_clients[coin_type]['datadir']
|
||||||
command_cli = os.path.join(bindir, chainparams[coin_type]['name'] + '-cli' + ('.exe' if os.name == 'nt' else ''))
|
command_cli = os.path.join(bindir, chainparams[coin_type]['name'] + '-cli' + ('.exe' if os.name == 'nt' else ''))
|
||||||
chainname = '' if self.chain == 'mainnet' else (' -' + self.chain)
|
args = [command_cli, ]
|
||||||
args = command_cli + chainname + ' ' + '-datadir=' + datadir + ' ' + params
|
if self.chain != 'mainnet':
|
||||||
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
args.append('-' + self.chain)
|
||||||
|
args.append('-datadir=' + datadir)
|
||||||
|
args += shlex.split(params)
|
||||||
|
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
out = p.communicate(timeout=timeout)
|
out = p.communicate(timeout=timeout)
|
||||||
if len(out[1]) > 0:
|
if len(out[1]) > 0:
|
||||||
raise ValueError('CLI error ' + str(out[1]))
|
raise ValueError('CLI error ' + str(out[1]))
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
# Copyright (c) 2020 tecnovert
|
# Copyright (c) 2020-2022 tecnovert
|
||||||
# Distributed under the MIT software license, see the accompanying
|
# Distributed under the MIT software license, see the accompanying
|
||||||
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
# file LICENSE or http://www.opensource.org/licenses/mit-license.php.
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import json
|
import json
|
||||||
|
import shlex
|
||||||
import urllib
|
import urllib
|
||||||
import logging
|
import logging
|
||||||
import traceback
|
import traceback
|
||||||
|
@ -129,8 +130,13 @@ def openrpc(rpc_port, auth, wallet=None, host='127.0.0.1'):
|
||||||
def callrpc_cli(bindir, datadir, chain, cmd, cli_bin='particl-cli'):
|
def callrpc_cli(bindir, datadir, chain, cmd, cli_bin='particl-cli'):
|
||||||
cli_bin = os.path.join(bindir, cli_bin)
|
cli_bin = os.path.join(bindir, cli_bin)
|
||||||
|
|
||||||
args = cli_bin + ('' if chain == 'mainnet' else (' -' + chain)) + ' -datadir=' + datadir + ' ' + cmd
|
args = [cli_bin, ]
|
||||||
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
|
if chain != 'mainnet':
|
||||||
|
args.append('-' + chain)
|
||||||
|
args.append('-datadir=' + datadir)
|
||||||
|
args += shlex.split(cmd)
|
||||||
|
|
||||||
|
p = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
out = p.communicate()
|
out = p.communicate()
|
||||||
|
|
||||||
if len(out[1]) > 0:
|
if len(out[1]) > 0:
|
||||||
|
|
Loading…
Reference in a new issue