Python: NullPointerException for os.system() and os.popen()
Question: I am getting a `NullPointerException` for `os.system()` and `os.popen()` on
python 2.2.1. The weird thing is that i have two servers and this same code
works fine on one but not on the other. What could be missing in the second
server?

Below is the code snippet

    
    
    import sys
    import os
    
    print (sys.version)   #This line works on both servers and gives 2.2.1 os output 
    os.system('pwd')
    os.popen('hostname -f').read().rstrip('\n')
    

I get the following error in the second server:

    
    
    *File "/u01/oracle/mwhome/wlserver_10.3/common/wlst/modules/jython-modules.jar/Lib/javaos$py.class", line 333, in system
    File "/u01/oracle/mwhome/wlserver_10.3/common/wlst/modules/jython-modules.jar/Lib/popen2.py", line 31, in ?
    File "/u01/oracle/mwhome/wlserver_10.3/common/wlst/modules/jython-modules.jar/Lib/javashell.py", line 17, in ?
    File "/u01/oracle/mwhome/wlserver_10.3/common/wlst/modules/jython-modules.jar/Lib/string$py.class", line 434, in ?
        at java.io.File.<init>(File.java:222)
        at java.lang.Package$1.run(Package.java:527)
        at java.lang.Package.defineSystemPackage(Package.java:520)
        at java.lang.Package.getSystemPackages(Package.java:511)
        at java.lang.ClassLoader.getPackages(ClassLoader.java:1513)
        at java.lang.ClassLoader.getPackages(ClassLoader.java:1511)
        at java.lang.Package.getPackages(Package.java:281)
        at org.python.core.JavaImportHelper.buildLoadedPackages(Unknown Source)
        at org.python.core.JavaImportHelper.tryAddPackage(Unknown Source)
        at org.python.core.imp.import_next(Unknown Source)
        at org.python.core.imp.import_name(Unknown Source)
        at org.python.core.imp.importName(Unknown Source)
        at org.python.core.ImportFunction.load(Unknown Source)
        at org.python.core.ImportFunction.__call__(Unknown Source)
        at org.python.core.PyObject.__call__(Unknown Source)
        at org.python.core.__builtin__.__import__(Unknown Source)
        at org.python.core.imp.importFromAs(Unknown Source)
        at org.python.core.imp.importFrom(Unknown Source)
        at string$py.f$0(C:\wlst\jython_2.2.1\Lib\string.py:434)
        at string$py.call_function(C:\wlst\jython_2.2.1\Lib\string.py)
        at org.python.core.PyTableCode.call(Unknown Source)
        at org.python.core.PyCode.call(Unknown Source)
        at org.python.core.imp.createFromCode(Unknown Source)
        at org.python.core.imp.createFromPyClass(Unknown Source)
        at org.python.core.ZipFileImporter$ZipFileLoader.load_module(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
    java.lang.NullPointerException: java.lang.NullPointerException*
    


Answer: I could be wrong here but I noticed that there is 'C:\' in the stacktrace. If
this is running on a windows system 'pwd' and 'hostname' likely wont work if
os.system / popen are executing exactly what you put in the argument which is
likely why you are getting the error.

I am not a windows guru by any means but I dont think those commands exist
outside of *nix based OS's.

