Skip to content

Instantly share code, notes, and snippets.

@jcfr
Created February 6, 2013 22:21
Show Gist options
  • Save jcfr/4726448 to your computer and use it in GitHub Desktop.
Save jcfr/4726448 to your computer and use it in GitHub Desktop.
Example illustrating how a cli could be executed directly using subprocess.Popen. This could be particularly useful when investigating issue associated with CLI. Source: http://stackoverflow.com/questions/706989/how-to-call-an-external-program-in-python-and-retrieve-the-output-and-return-cod
import os
from subprocess import Popen, PIPE
#cli_path = "/home/jchris/Projects/Slicer-AHM-Superbuild-Debug/Slicer-build/lib/Slicer-4.2/cli-modules"
#cli_name = "AddScalarVolumes"
#cli_filepath = os.path.join(cli_path, cli_name)
cli_filepath = slicer.modules.addscalarvolumes.path
process = Popen([cli_filepath, "--xml"], stdout=PIPE)
output = process.communicate()[0]
print(output)
@fbudin69500
Copy link

Since my module was not loading in Slicer, I had to use the commented piece of code and comment out "slicer.modules.addscalarvolumes.path". Very useful though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment