Message9313

Author zyasoft
Recipients fwierzbicki, shishir, zyasoft
Date 2015-01-06.17:45:25
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1420566325.72.0.644343530889.issue2238@psf.upfronthosting.co.za>
In-reply-to
Content
Shishir, we did tag the beta yesterday, so this should be released shortly.

I reviewed our implementation of os.system. Right now, it's Java code that's directly wrapping a call to Python. This is unnecessary:

    public static PyString __doc__system = new PyString(
        "system(command) -> exit_status\n\n" +
        "Execute the command (a string) in a subshell.");
    public static PyObject system(PyObject command) {
        // import subprocess; return subprocess.call(command, shell=True)
        return imp.load("subprocess").invoke("call", command, new PyObject[] {Py.True},
                                             new String[] {"shell"});
    }

(PosixModule.java)

The other thing is that it uses subprocess in its implementation. I believe the right thing to do is to rewrite as follows:

from java.lang import Runtime

def system(command)
    """system(command) -> exit_status

    Execute the command (a string) in a subshell."""
    return Runtime.exec(command).exitValue()

Easy!

This avoids using subprocess and possibly any problems in its implementation on a specific system, as we have seen in HPUX. Presumably it would just work then, given the simplicity of the above code. No monkeypatching needed as well by Shishir, always a bonus! :)

The other thing is that it better corresponds to the docs seen here: https://docs.python.org/2/library/os.html#os.system
History
Date User Action Args
2015-01-06 17:45:25zyasoftsetmessageid: <1420566325.72.0.644343530889.issue2238@psf.upfronthosting.co.za>
2015-01-06 17:45:25zyasoftsetrecipients: + zyasoft, fwierzbicki, shishir
2015-01-06 17:45:25zyasoftlinkissue2238 messages
2015-01-06 17:45:25zyasoftcreate