schrodinger.utils.subprocess module

A wrapper to the standard library subprocess module.

This module automatically checks for executables in the $SCHRODINGER and $SCHRODINGER/utilities to make it absolute, and adds an interpreter to the command where appropriate.

A general limitation of this module is that the subprocess commands must be specified as lists of strings. This is a conscious design decision meant to avoid issues with quoting arguments that contain spaces.

Copyright Schrodinger, LLC. All rights reserved.

schrodinger.utils.subprocess.abs_schrodinger_path(prog_name)[source]

Search for prog_name in the $SCHRODINGER and $SCHRODINGER/utilities directories. If found, returns prog_name prepended with the correct directory path. If not found, prog_name is returned unchanged.

Parameters

prog_name (str) – name of the executable to search for

schrodinger.utils.subprocess.call(cmd, **kwargs)[source]

Run a command with arguments and wait for it to return. Return the exit status.

Look for executables in $SCHRODINGER and $SCHRODINGER/utilities, and provide an interpreter if needed.

Parameters

cmd (list of str) – The command to be run, specified as a list of strings.

Return type

int

Returns

Exit status of the command.

schrodinger.utils.subprocess.check_call(cmd, **kwargs)[source]

Run a command with arguments and wait for it to return. Raises an exception if the command exits with a non-zero exit status. Return the exit status.

Look for executables in $SCHRODINGER and $SCHRODINGER/utilities, and provide an interpreter if needed.

Parameters

cmd (list of str) – The command to be run, specified as a list of strings.

Return type

int

Returns

Exit status of the command.

Raises

subprocess.CalledProcessError – If the exit code is not 0.

schrodinger.utils.subprocess.check_output(cmd, **kwargs)[source]

Run a command with arguments and wait for it to return. Raises an exception if the command exits with a non-zero exit status. Return the

Look for executables in $SCHRODINGER and $SCHRODINGER/utilities, and provide an interpreter if needed.

Parameters

cmd (list of str) – The command to be run, specified as a list of strings.

Return type

str

Returns

StdOut of the command.

Raises

subprocess.CalledProcessError – If the exit code is not 0.

schrodinger.utils.subprocess.Popen(cmd, **kwargs)[source]

A wrapper for the builtin subprocess module’s Popen class. This function will return a subprocess Popen instance, passing all kwargs on to the underlying class.

The only difference is that it will automatically look for executables in $SCHRODINGER and $SCHRODINGER/utilities, and provide an interpreter if needed.

Parameters

cmd (list of str) – The command to be run, specified as a list of strings.

schrodinger.utils.subprocess.kill_process(pid)[source]

Kill the process and all its children. :param int pid: Process id to kill.