簡體   English   中英

在命令提示符下運行 Windows 掃描程序以獲取來自 Java 的文件

[英]Running Windows Scanner in command prompt for a file From Java

我正在嘗試從 Java 以編程方式掃描文件,並希望在命令行上執行此操作。

我直接在命令行中工作(簡單導航到文件夾並執行命令:

c:\Users\3XXXXX8\Desktop>cd "C:\\Program Files\\Windows Defender" && MpCmdRun.exe -Scan -ScanType 3 -File "C:\\UploadedFiles\\file"
Scan starting...
Scan finished.
Scanning C:\\UploadedFiles\\file found no threats.

我希望它從 Java 工作。 我對我應該為Process 提供的字符串感到困惑。 我發現有些地方應該用 \\c 輸入命令字符串,因為它是寡婦。 但這不起作用。 程序如下。 String [] 命令需要修復。

import java.io.*;

    public class CmdTest {
        public static void main(String[] args) throws Exception {
            String [] commands = {
                "cmd /c \"cd \"C:\\Program Files\\Windows Defender\" && MpCmdRun.exe -Scan -ScanType 3 -File \"C:\\UploadedFiles\\file\"\""
            }
            ProcessBuilder builder = new ProcessBuilder(commands);
            builder.redirectErrorStream(true);
            Process p = builder.start();
            BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()));
            String line;
            while ( (line = r.readLine()) != null) {
                System.out.println(line);
            }
        }
    }

請幫忙。

我為命令字符串嘗試過的其他一些組合:

String [] commands = { "cmd.exe", "/c", "cd \"C:\\Program Files\\Windows Security Client\"",
                    "MpCmdRun.exe -Scan -ScanType 3 -File C:\\UploadedFiles\\" + file.getName()
            };

String [] commands = {
            "cmd /c \"cd \"C:\\Program Files\\Windows Defender\" && MpCmdRun.exe -Scan -ScanType 3 -File \"C:\\UploadedFiles\\file\"\""
        }


String [] commands = {
                "cmd \"cd \"C:\\Program Files\\Windows Defender\" && MpCmdRun.exe -Scan -ScanType 3 -File \"C:\\UploadedFiles\\file\"\""
            }

不知道怎么破解。

String [] commands = {
            "\"C:\\Program Files\\Windows Defender\\MpCmdRun.exe\" -Scan -ScanType 3 -File \"C:\\UploadedFiles\\file\""
        };

這對我有用^。

我不需要“cmd / c”

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM