-1

below is my code this is a mini IDE for a class project I am stuck here am trying to build an IDE that compiles java. I downloaded JDK and am using subprocess to pipe cmd and communicate with javac but I need to pass the file name with extension so it just shows output and I also need help with outputting a console because it tends to only open in visual studio terminal please help me because I will be submitting on Thursday. femi.femiii@gmail.com

from tkinter import filedialog
from tkinter import messagebox
import subprocess
import os

name_file = os.path.basename(__file__)


    # run button that opens command line
    def run(self, *args):

        p1 = subprocess.Popen('cmd', shell=True, stdin=None, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        p2 = subprocess.Popen('javac name_file; java name_file', shell=True, stdin=p1.stdout)
        p1.stdout.close()
        out, err = p2.communicate()


if __name__ == "__main__":
    master = tk.Tk()
    pt = PyText(master)
    master.mainloop()```

femiir
  • 190
  • 1
  • 2
  • 15
  • Please reduce this code down to a [mcve]. If the issue you're having is with passing a filename to a subprocess, we only need enough code to show you trying to do that. – Bryan Oakley Nov 11 '19 at 15:41

1 Answers1

0

The easiest way I can think of would be to use sys argv's to pass the file name to a node or java routine

modify your python script to pass info to command line in argv

fname = file 
#file you want to pass 
pythonCall = 'node javascript.js -- '+fname
#the -- passes what follows into the sys argvs
#this is python notation, java/node may not need the '--' but just a space
runCommand = 'cmd.exe /c ' + pythonCall
subprocess.Popen(runCommand)

then at the start of your javascript, this will give you the file name that was passed into argv, its from the link I included below.

var args = process.argv.slice(2);

if you need more help accessing process.argv in java:

How do I pass command line arguments to a Node.js program?

John T
  • 234
  • 1
  • 6
  • am not using javascript I mean a real java program program – femiir Nov 12 '19 at 05:11
  • It's the same idea, and java has the file input already builtin as an argument for command line so its even simpler. I would first double check that the 'name_file' part is being read properly by command line, part of the reason I have my line pythonCall = 'node javascript.js -- '+fname, is to ensure that the full path is sent to command line. next I would make sure the compile command is finishing before the run command, if it's not, python has a wait() command that should solve that problem. this would require you to break your compile and run commands into separate Subprocess calls. – John T Nov 12 '19 at 15:54