批处理文件的替代品,因为我无法在其中包含Java代码

我听说java代码无法在我之前的问题评论中添加到批处理文件中:

但它有什么替代品吗?
是否可以将Java代码添加到批处理文件中?

我在批处理文件中尝试了以下操作,但它不起作用:

vol231.exe -f m.walkin(新文件(d.detectDrive()))imageinfo> Volatility.txt

这是我创建的cmdenv.bat,可以在java的命令提示符下运行:

E: echo off cls ... //This part is a long part for reducing footprint whereby the command prompt is switched to Helix vol231.exe -f E:\KOHMOHOJOJO-PC-20140714-152414.raw imageinfo > Volatility.txt vol231.exe -f E:\KOHMOHOJOJO-PC-20140714-152414.raw --profile=Win7SP0x86 pslist >> Volatility.txt pause exit 

这允许我的波动率命令在封闭的命令提示符(Helix)中运行,这减少了占用空间。

但是,波动率命令都是硬编码的。 E:\KOHMOHOJOJO-PC-20140714-152414.raw--profile=Win7SP0x86各不相同。 有没有其他选择,因为批处理文件允许java编码?

我是java和批处理文件的新手。

EDIT1: 在此处输入图像描述在此处输入图像描述

我尝试更改java_path但它仍然有错误。

Edit2:我试过不同的路径,比如:

  1. C:\Program Files\Java\jdk1.8.0_05\binC:\Program Files\Java\jre8\bin我收到Error: Could not find or load main class TestRun1

  2. C:\Users\User\workspace\Volatility\binC:\Users\User\workspace\Volatility\src (这是保存类的工作空间)我得到C:\Users\User\workspace\Volatility\(bin or src)\java不被识别为内部或外部命令,可操作程序或批处理文件。 所以我将java.exe添加到文件中。 并且错误返回Error: Could not find or load main class TestRun1

这个批处理文件似乎无法读取java ..我试过添加一个.TestRun1前面,但它仍然有相同的错误。 我还发现我在Control Panel\System and Security\System\Advance System Settings\Environment Variables (Path)下有Control Panel\System and Security\System\Advance System Settings\Environment Variables 。 我尝试删除C:\Program Files\Java\jdk1.8.0_05\bin然后运行它但它仍然有相同的错误。

那么可以将java代码添加到批处理文件中吗?

,您无法将Java代码添加到批处理文件中。

替代解决方法:

要在批处理文件中使用Java值,请在Java中打印该值,在批处理文件中使用该值。

在Java中

 public class TestRun1 { public static void main(String args[]) { System.out.println(m.walkin(new File(d.detectDrive()))); } } 

在批处理文件中:

 set tmp_file=%TEMP%\%~n0.tmp rem ----set as per your java directory------- set java_path=C:\Program Files\Java\jdk1.6.0_43\bin "%java_path%\java" TestRun1> "%tmp_file%" set /P p=<"%tmp_file%" echo %p% rem -----now p has the value, use it in the command-------- vol231.exe -f %p% imageinfo > Volatility.txt vol231.exe -f %p% --profile=Win7SP0x86 pslist >> Volatility.txt vol231.exe -f %p% --profile=Win7SP0x86 dlllist > Volatility.txt vol231.exe -f %p% --profile=Win7SP0x86 iehistory >> Volatility.txt vol231.exe -f %p% --profile=Win7SP0x86 svcscan >> Volatility.txt vol231.exe -f %p% --profile=Win7SP0x86 hivelist >> Volatility.txt vol231.exe -f %p% --profile=Win7SP0x86 filescan >> Volatility.txt vol231.exe -f %p% --profile=Win7SP0x86 netscan >> Volatility.txt pause del /F "%tmp_file%" 

使Java程序将文件名作为命令行选项传递给批处理文件。 在批处理文件中,您可以将其作为变量%1 。 您可以传递多个命令行选项; 其他的将以%2%3等forms提供。

在这里你如何将java代码添加到批处理文件中(虽然它不是完全解决你的问题的完整解决方案):

  @Deprecated /* >nul 2>&1 :: self compiled java/.bat hybrid :: :: deprecated is the only one annotation that can be used outside the class definition :: and is needed for 'mute' start of multi-line java comment :: that will be not printed by the batch file. :: though it still created two files - the .class and the .java :: it still allows you to embed both batch and java code into one file @echo off setlocal java -version >nul 2>&1 || ( echo java not found exit /b 1 ) ::find class name for /f "usebackq tokens=3 delims=} " %%c in (`type %~f0 ^|find /i "public class"^|findstr /v "for /f"`) do ( set "javaFile=%%c" goto :skip ) :skip copy "%~f0" "%javaFile%.java" >nul 2>&1 javac "%javaFile%.java" java "%javaFile%" ::optional ::del %javaFile%.* >nul 2>&1 end local exit /b 0 *******/ public class TestClass { public static void main(String args[]) { System.out.println("selfcompiled .bat/.java hybrid"); } } 

不推荐使用的注释是我发现的唯一可以在类外设置的注释。需要注释以避免有毒输出。它还会创建两个可以删除的临时文件(.class和.java)。