简体   繁体   English

如何在Java Swing中集成防病毒命令

[英]How to integrate Antivirus Commands in Java Swing

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. 有许多命令行,例如使用命令行(Avast)使用终端安装或删除适用于Mac OS X的Sophos Anti-Virus等,以运行防病毒软件,但我的要求是将它们嵌入GUI应用程序,然后从那里运行。 Basically it will be best to embed these command in Java Swing Application. 基本上,最好将这些命令嵌入Java Swing应用程序中。

But I have no idea how to do it, if any one has references to sources regarding this please let me know. 但是我不知道该怎么做,如果有人引用了与此相关的资料,请告诉我。

Better to read up upon how to run external programs through the Java. 最好阅读一下如何通过Java运行外部程序。 You can easily use Process and ProcessBuilder classes to get the stuffs done. 您可以轻松地使用ProcessProcessBuilder类来完成工作。 Readers and Writers will be needed when you are dealing with argument passing kind of stuffs. 当您处理传递参数的东西时,将需要读者和作家。

eg 例如

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. 这将仅打开命令提示符并执行dir命令,该命令将列出当前文件夹中的文件夹和文件列表。 You can handle inputs and outputs through 您可以通过以下方式处理输入和输出

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

Check this out 看一下这个

In java you can use ProcessBuilder class to execute any process or executable.Syntax for ProcessBuilder is as follows: 在Java中,您可以使用ProcessBuilder类来执行任何进程或可执行文件.ProcessBuilder的语法如下:

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: 现在,当您要运行avast防病毒引擎时,可以使用ProcessBuilder如下运行它:

 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. 上面的代码将扫描D:驱动器中的pathtoscan文件夹。类似地,您可以传递avast的不同参数,如其网站上所述。

Hope this answer your question. 希望这个回答您的问题。

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

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