From c4997429a28908c6fe1383d91ba8c5324d5e5fd7 Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Sat, 15 Apr 2017 11:34:03 -0700 Subject: [PATCH] Don't use shell=true in subprocess, and instead hide the console window in Windows using the startupinfo arg --- onionshare/onion.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/onionshare/onion.py b/onionshare/onion.py index 81e1dfd5..d0908cb3 100644 --- a/onionshare/onion.py +++ b/onionshare/onion.py @@ -176,9 +176,17 @@ class Onion(object): torrc_template = torrc_template.replace('{{socks_port}}', str(self.tor_socks_port)) open(self.tor_torrc, 'w').write(torrc_template) - # Open tor in a subprocess, wait for the controller to start + # Execute a tor subprocess start_ts = time.time() - self.tor_proc = subprocess.Popen([self.tor_path, '-f', self.tor_torrc], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + if system == 'Windows': + # In Windows, hide console window when opening tor.exe subprocess + startupinfo = subprocess.STARTUPINFO() + startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW + self.tor_proc = subprocess.Popen([self.tor_path, '-f', self.tor_torrc], stdout=subprocess.PIPE, stderr=subprocess.PIPE, startupinfo=startupinfo) + else: + self.tor_proc = subprocess.Popen([self.tor_path, '-f', self.tor_torrc], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + # Wait for the tor controller to start time.sleep(0.2) # Connect to the controller