繁体   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