链接到批处理文件的java变量 [英] java variable linked to batch file

查看:50
本文介绍了链接到批处理文件的java变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在学习Java,并且遇到了此问题.由于我仍处于学习阶段,我不确定是否可以这样做.因此,在我的Java主要编码中:

I am currently learning java and I encountered this problem. I am not sure if it can be done like this as I am still in the learning stage. So in my java main coding:

import java.io.File;
import java.io.IOException;

public class TestRun1
{
    public static void main(String args[])
    {

        //Detect usb drive letter
        drive d = new drive();
        System.out.println(d.detectDrive());

        //Check for .raw files in the drive (e.g. E:\)
        MainEntry m = new MainEntry();
        m.walkin(new File(d.detectDrive()));

        try
        {
            Runtime rt = Runtime.getRuntime();
            Process p = rt.exec("cmd /c start d.detectDrive()\\MyBatchFile.bat");
        } 
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}

"cmd/c start d.detectDrive()\ MyBatchFile.bat"不起作用.我不知道如何替换变量.

The "cmd /c start d.detectDrive()\MyBatchFile.bat" does not work. I do not know how to replace the variable.

然后我创建了一个批处理文件(MyBatchFile.bat):

And i created a batch file (MyBatchFile.bat):

@echo off
set Path1 = d.detectDrive()
Path1
pause
set Path2 = m.walkin(new File(d.detectDrive()))
vol231.exe -f Path2 imageinfo > Volatility.txt
pause
exit

它不起作用.请不要笑.

It does not work. Please do not laugh.

由于我刚开始使用Java和批处理文件,因此我确实在编程方面并不擅长.有人可以帮我吗?我不想对其进行硬编码以使其成为E:或类似的东西.我想使其变得灵活.但是我不知道该怎么做.我真诚地寻求帮助.

I really isn't good in programming since I just started on java and batch file. Can anyone help me with it? I don't want to hard code it to become a E: or something like that. I want to make it flexible. But I have no idea how to do it. I sincerely ask for any help.

推荐答案

过程:

您应该将检测驱动器的方法的返回值附加到文件名中,并组成正确的Batch命令字符串.

Procedure:

You should append the return value of the method which detects the drive, to the filename and compose the proper Batch command string.

  • 字符串驱动器= d.detectDrive();
  • 因此,驱动器包含值 E:
  • drive +"\ MyBatchFile.bat"
  • 因此,我们有 E:\ MyBatchFile.bat
  • cmd/c开始"+ drive +" \ MyBatchFile.bat
  • 结果为 cmd/c start E:\ MyBatchFile.bat
    try {
        System.out.println(d.detectDrive()); 
        Runtime rt = Runtime.getRuntime();
        String drive = d.detectDrive();
        // <<---append the return value to the compose Batch command string--->>
        Process p = rt.exec("cmd /c start "+drive+"\\MyBatchFile.bat");
    } 
    catch (IOException e) {
        e.printStackTrace();
    }

这篇关于链接到批处理文件的java变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆