创建和执行批处理文件并将输出链接到进度条 [英] Creating and executing batch file and linking the output to a progress bar

查看:33
本文介绍了创建和执行批处理文件并将输出链接到进度条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个 Java swing GUI,它从用户(通过文本字段)获取很少的参数并将它们存储在一个名为 finalstring 的字符串中.这个字符串基本上是一个命令,它运行一个带有很少参数的.exe"文件.现在我想创建一个批处理文件(桌面上的start.bat),我想在其中复制这个字符串.最后我想执行这个批处理文件.随着执行,我还想存储这个批处理文件的输出.此外,批处理文件执行某些进程,我想将其与进度条链接,这可能吗?(在批处理文件中运行的进程,要链接到 java swing 的进度条?).

I am creating a Java swing GUI, which takes few parameters from user (through text fields) and stores them in a string called finalstring. This string is basically a command, which runs an ".exe" file with few parameters. Now i want to create a batch file(start.bat on my desktop), in which i want to copy this string. Finally i want to execute this batch file. Along with the execution, i also want to store the output of this batch file. Also, the batch file executes certain process, which i want to link with progress bar, is this possible?(process running in batch file, to be linked to java swing's progress bar?).

我使用python和tkinter作为GUI做了以上所有事情,但是在批处理文件的输出存储期间,我的tkinter gui曾经挂起(没有响应),所以我切换到java swings GUI.我搜索了大部分在线线程,但我的脑海中没有任何内容(还创建了几个 Java 程序,但没有创建批处理文件),所以我需要帮助,感谢您为浏览此线程所做的努力.

I did all above things using python and tkinter as GUI, but during the storage of output of batch file, my tkinter gui used to hang(not responding), so i am switching to java swings GUI. I searched most of the online threads, but nothing is going in my head(created few java programs also, but the batch file is not being created), so i want help, i appreciate your effort to go through this thread.

推荐答案

您可以使用 ProcessBuilder,如图此处>.您可以将组合输出流中的 append() 行添加到 JTextArea,如下所示 这里.

You can execute your batch using ProcessBuilder, as shown here. You can append() lines from the combined output stream to a JTextArea, as shown here.

我不确定您是否可以在 JProgressBar 不知道更多关于进程的粒度.

I'm not sure you can usefully display progress in a JProgressBar without knowing more about the granularity of the process.

这篇关于创建和执行批处理文件并将输出链接到进度条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆