-1

There are many command lines like Using the command line(Avast), Using the Terminal to install or remove Sophos Anti-Virus for Mac OS X etc. for antivirus running but my requirement is to embed them in an GUI Application and then run from there. Basically it will be best to embed these command in Java Swing Application.

But I have no idea how to do it, if any one has references to sources regarding this please let me know.

Dijkgraaf
  • 11,049
  • 17
  • 42
  • 54
Ajeet Varma
  • 726
  • 4
  • 20

2 Answers2

3

Better to read up upon how to run external programs through the Java. You can easily use Process and ProcessBuilder classes to get the stuffs done. Readers and Writers will be needed when you are dealing with argument passing kind of stuffs.

e.g.

Process p = Runtime.getRuntime().exec("cmd /c dir");

this will simply open the command prompt and execute dir command which will list the folders and file list in the current folder. You can handle inputs and outputs through

InputStream in = process.getInputStream();
OutputStream out = process.getOutputStream();

Check this out

  • Thanks a lot , it's working fine , One more help please , if i will have to run many command , then what should i follow .. ; again thanks a lot .. – Ajeet Varma Aug 13 '14 at 07:35
  • @AjeetVarma There are overload exec() methods. Check on this link http://www.javaworld.com/article/2071275/core-java/when-runtime-exec---won-t.html – Thusitha Thilina Dayaratne Aug 13 '14 at 08:01
1

In java you can use ProcessBuilder class to execute any process or executable.Syntax for ProcessBuilder is as follows:

Process process = new ProcessBuilder("C:\\PathToExe\\MyExe.exe","param1","param2").start();

Now as you want to run avast antivirus engine you can run its using ProcessBuilder as follows:

 Process process = new ProcessBuilder("C:\\Program Files\\AVAST Software\\avast\\ashCmd.exe","D:\\pathtoscan");

The above code will scan pathtoscan folder in D: Drive.Similarly you can pass different parameters for avast as mentioned on their website.

Hope this answer your question.

Sachin Janani
  • 1,310
  • 1
  • 17
  • 33