Merge "simpleperf: fix scripts based on test on darwin/windows."
am: b137bb2c74

Change-Id: I330a053333edb0d2b686d6dd1a63147951d614cf
diff --git a/simpleperf/doc/README.md b/simpleperf/doc/README.md
index 2e33a1e..db58485 100644
--- a/simpleperf/doc/README.md
+++ b/simpleperf/doc/README.md
@@ -764,7 +764,7 @@
 
 On Windows platform:
 
-    $ ./inferno.bat -sc --symfs binary_cache
+    $ inferno.bat -sc --symfs binary_cache
 
 Remove `--symfs binary_cache` if you selected not to collect binaries when
 using `app_profiler.py`.
diff --git a/simpleperf/doc/inferno.md b/simpleperf/doc/inferno.md
index 2f33e8d..bfe280a 100644
--- a/simpleperf/doc/inferno.md
+++ b/simpleperf/doc/inferno.md
@@ -52,7 +52,7 @@
 Open a terminal and from `simpleperf/scripts` directory type:
 ```
 ./inferno.sh  (on Linux/Mac)
-./inferno.bat (on Windows)
+inferno.bat (on Windows)
 ```
 
 Inferno will collect data, process them and automatically open your web browser
diff --git a/simpleperf/scripts/inferno.bat b/simpleperf/scripts/inferno.bat
index 3021d50..a2d18a7 100644
--- a/simpleperf/scripts/inferno.bat
+++ b/simpleperf/scripts/inferno.bat
@@ -1 +1 @@
-python -m inferno.inferno %
+python -m inferno.inferno %*
diff --git a/simpleperf/scripts/inferno/inferno.py b/simpleperf/scripts/inferno/inferno.py
index 15d7776..b4fd97a 100644
--- a/simpleperf/scripts/inferno/inferno.py
+++ b/simpleperf/scripts/inferno/inferno.py
@@ -214,13 +214,17 @@
 
 
 def open_report_in_browser(report_path):
-    # Try to open the report with Chrome
-    browser_key = ""
-    for key, value in webbrowser._browsers.items():
-        if key.find("chrome") != -1:
-            browser_key = key
-    browser = webbrowser.get(browser_key)
-    browser.open(report_path, new=0, autoraise=True)
+    try:
+        # Try to open the report with Chrome
+        browser_key = ""
+        for key, value in webbrowser._browsers.items():
+            if key.find("chrome") != -1:
+                browser_key = key
+        browser = webbrowser.get(browser_key)
+        browser.open(report_path, new=0, autoraise=True)
+    except:
+        # webbrowser.get() doesn't work well on darwin/windows.
+        webbrowser.open_new_tab(report_path)
 
 
 def main():
diff --git a/simpleperf/scripts/test.py b/simpleperf/scripts/test.py
index aa9763f..ea66fee 100644
--- a/simpleperf/scripts/test.py
+++ b/simpleperf/scripts/test.py
@@ -92,11 +92,12 @@
     def run_cmd(self, args, return_output=False):
         if args[0].endswith('.py'):
             args = [sys.executable] + args
+        use_shell = args[0].endswith('.bat')
         try:
             if not return_output:
-                returncode = subprocess.call(args)
+                returncode = subprocess.call(args, shell=use_shell)
             else:
-                subproc = subprocess.Popen(args, stdout=subprocess.PIPE)
+                subproc = subprocess.Popen(args, stdout=subprocess.PIPE, shell=use_shell)
                 (output_data, _) = subproc.communicate()
                 returncode = subproc.returncode
         except: