• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

No text displayed, JTextArea.append();?

 
Aces Kok Ben
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, what I was trying to do is to run this Antivirus app called "clamscan.exe" and I want to display out (on a particular JTextArea) whatever the output the Antivirus stream out. Here are my codes:



The thing is, the System.out.println(input.readLine()); could print out the and display the output of the Antivirus while it was scanning, but the jTextArea (a jTextArea). doesn't. Why is this so? The thing I don't understand is, when I kill the process clamscan.exe from the Task manager, the output will then be displayed on the textArea. What happened?
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Concurrency in Swing. You'll need a separate thread (or SwingWorker) to read the stream.
Also, read When Runtime.exec() won't. Either use ProcessBuilder and call redirectErrorStream(true), or create a second thread / SwingWorker for reading the error stream.
 
Aces Kok Ben
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:Concurrency in Swing. You'll need a separate thread (or SwingWorker) to read the stream.
Also, read When Runtime.exec() won't. Either use ProcessBuilder and call redirectErrorStream(true), or create a second thread / SwingWorker for reading the error stream.


Mm... I don't really get what you mean. Your words are slightly too technical for me. Can you give me some examples.

EDITED:



I tried running the following codes but it gives me the error of

"Cannot run program "clamscan.exe --database="C:\Users\Aces\workspace\Year2Sem1\InfoSecurityProject\db" --recursive C:\" (in directory "C:\Users\Aces\workspace\Year2Sem1\InfoSecurityProject\mainbin"): CreateProcess error=2, The system cannot find the file specified"

I'm sure the clamwin.exe is there, however, it says it cannot find the file specified.
 
Paul Clapham
Sheriff
Posts: 21113
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aces Kok Ben wrote:Mm... I don't really get what you mean. Your words are slightly too technical for me. Can you give me some examples.

The links that Rob Spoor posted contain a lot of examples. You should read them instead of asking for people to make up new examples.
I tried running the following codes but it gives me the error of

"Cannot run program "clamscan.exe --database="C:\Users\Aces\workspace\Year2Sem1\InfoSecurityProject\db" --recursive C:\" (in directory "C:\Users\Aces\workspace\Year2Sem1\InfoSecurityProject\mainbin"): CreateProcess error=2, The system cannot find the file specified"

I'm sure the clamwin.exe is there, however, it says it cannot find the file specified.

That's perhaps because the code says to use "clamscan.exe" instead of "clamwin.exe". Fix the typo.

However if the typo is in your post here and you really believe that clamscan.exe is "there", then you should figure out where the shell program you're running considers to be "there". Evidently you don't understand where "there" is.
 
Aces Kok Ben
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Paul Clapham wrote:
Aces Kok Ben wrote:Mm... I don't really get what you mean. Your words are slightly too technical for me. Can you give me some examples.

The links that Rob Spoor posted contain a lot of examples. You should read them instead of asking for people to make up new examples.
I tried running the following codes but it gives me the error of

"Cannot run program "clamscan.exe --database="C:\Users\Aces\workspace\Year2Sem1\InfoSecurityProject\db" --recursive C:\" (in directory "C:\Users\Aces\workspace\Year2Sem1\InfoSecurityProject\mainbin"): CreateProcess error=2, The system cannot find the file specified"

I'm sure the clamwin.exe is there, however, it says it cannot find the file specified.

That's perhaps because the code says to use "clamscan.exe" instead of "clamwin.exe". Fix the typo.

However if the typo is in your post here and you really believe that clamscan.exe is "there", then you should figure out where the shell program you're running considers to be "there". Evidently you don't understand where "there" is.


I did read the examples and even tried out myself, the problem is I can't understand what it means.

Sorry and I meant clamscan.exe not clamwin.exe (typo error in the previous post)

EDITED:

I took a screenshot of a new set of codes I tried:

http://i53.tinypic.com/25pqzpk.jpg
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What happens if you execute this command from a command line prompt, in the same directory?
 
Aces Kok Ben
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Rob Spoor wrote:What happens if you execute this command from a command line prompt, in the same directory?


It works. I remember you mentioned creating another thread, but I'm not sure if you mean this:



Thread t is based on my Thread I created:

 
Ranganathan Kaliyur Mannar
Bartender
Posts: 1101
10
Java Netbeans IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let me try and explain what Rob means.

Basically you are calling exec() method and running a process. This starts the process and returns the Process object - with which you can find out the status of the process, send input to process, get output from process - you are using the last one. When you are getting the output from the process, the process is still running. So, its a separate 'thread of execution' you are interacting with. And its a long-running process (SwingWorker API had an advise on why you should not run time-consuming stuff within GUI listeners). And you are doing this all within the 'ActionListener' of the button (which is the swing thread). In Swing, whenever you want to update the GUI via a thread, you can't do it directly. Thats where the SwingWorker and 'Concurrency in Swing' comes in.

You should create the process from within the ActionListener and the rest (while loop and GUI updates) should be done from a SwingWorker.
 
Rob Spoor
Sheriff
Pie
Posts: 20545
56
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also,

1) do not call your class Thread; that causes confusion with java.lang.Thread. Never ever give your classes the same name as any class in the java.lang package.
2) when you call run() on a Runnable or Thread that will not start a new thread, but instead execute the thread's code in the current thread - in this case the Event Dispatcher Thread.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic