Compiling and Executing Java file in python
Question: how can I open an java file in python?, i've search over the net and found
this:

    
    
    import os.path, subprocess
    from subprocess import STDOUT, PIPE
    
    def compile_java (java_file):
        subprocess.check_call(['javac', java_file])
    
    def execute_java (java_file):
        cmd=['java', java_file]
        proc=subprocess.Popen(cmd, stdout = PIPE, stderr = STDOUT)
        input = subprocess.Popen(cmd, stdin = PIPE)
        print(proc.stdout.read())
    
    compile_java("CsMain.java")
    execute_java("CsMain")
    

but then I got this error:

    
    
    Traceback (most recent call last):
      File "C:\Python33\lib\subprocess.py", line 1106, in _execute_child
        startupinfo)
    FileNotFoundError: [WinError 2] The system cannot find the file specified
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "C:\casestudy\opener.py", line 13, in <module>
        compile_java("CsMain.java")
      File "C:\casestudy\opener.py", line 5, in compile_java
        subprocess.check_call(['javac', java_file])
      File "C:\Python33\lib\subprocess.py", line 539, in check_call
        retcode = call(*popenargs, **kwargs)
      File "C:\Python33\lib\subprocess.py", line 520, in call
        with Popen(*popenargs, **kwargs) as p:
      File "C:\Python33\lib\subprocess.py", line 820, in __init__
        restore_signals, start_new_session)
      File "C:\Python33\lib\subprocess.py", line 1112, in _execute_child
        raise WindowsError(*e.args)
    FileNotFoundError: [WinError 2] The system cannot find the file specified
    >>> 
    

the python file and java file is in the same folder, and I am using Python
3.3.2, how can I resolve this? or do you guys have another way on doing this?,
any answer is appreciated thanks!


Answer: I think it isn't recognizing the `javac` command. Try manually running the
command and if `javac` isn't a recognized command, register it in your `PATH`
variable and try again.

Or you could just try typing the full pathname to the Java directory for
`javac` and `java`.

