简体   繁体   English

如何使用 Java 中文本字段的用户输入运行.sh 脚本?

[英]How run .sh script with user input from textfield in Java?

I try start.sh script with user input from txtfield.我尝试使用来自 txtfield 的用户输入的 start.sh 脚本。 Idea: user write parametre in txt fild.思路:用户在 txt 字段中写入参数。 When push the button and script start with this parametre.当按下按钮和脚本开始这个参数。

My code:我的代码:

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) 
{                                         
String valueURL;
valueURL = URLtxt.getText().toString();              
ProcessBuilder processBuilder = new ProcessBuilder();
// -- Linux --
// Run a shell command
processBuilder.command("bash", "-c","nikto -h", valueURL,");     

try {

Process process = processBuilder.start();
StringBuilder output = new StringBuilder();
BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
output.append(line + "\n");         
}
int exitVal = process.waitFor();
if (exitVal == 0)                                            
 {
    this.hide();
    ScanWS sws = new ScanWS() ;
    sws.setVisible(true);
  1. An event istener is triggered in UI thread, so the processing must be fast .在 UI 线程中触发了一个事件监听器,因此处理必须很快 Your listener implementation waits for an external process , it can freeze your ui.您的侦听器实现等待外部进程,它可以冻结您的 ui。 All the process triggering and caring logic must start in a separate Thread.所有的进程触发和关心逻辑都必须在一个单独的线程中开始。

  2. A process is quite an old construction and it has input/output issue.一个过程是一个相当古老的结构,它有输入/输出问题。 A process writes something during it's work into a buffer of it's output stream and when the buffer is all filled - the process hungs , waiting for the output stream to make some space. A process writes something during it's work into a buffer of it's output stream and when the buffer is all filled - the process hungs , waiting for the output stream to make some space. So, both process.input and process.output processors also must work in separate threads.因此, process.inputprocess.output处理器也必须在单独的线程中工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM