簡體   English   中英

我如何使用子進程在 python tkinter 中傳遞文件名

[英]how can i pass a file name in python tkinter using subprocess

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. 我下載了 JDK 並正在使用 pipe cmd 的子進程並與 javac 通信,但我需要傳遞帶有擴展名的文件名,所以它只顯示 output,因為它傾向於在可視化終端中打開幫助,輸出控制台也需要幫助我,因為我將在星期四提交。 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()```

我能想到的最簡單的方法是使用 sys argv 將文件名傳遞給節點或 java 例程

修改您的 python 腳本以將信息傳遞到 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)

然后在 javascript 的開頭,這將為您提供傳遞給 argv 的文件名,它來自我在下面包含的鏈接。

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

如果您需要更多幫助來訪問 java 中的 process.argv:

如何將命令行 arguments 傳遞給 Node.js 程序?

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM