1

我有一个有趣的问题。我有一个 Java 应用程序,它创建一个批处理文件并且该批处理文件设置一个变量。现在,正在从另一个批处理文件调用应用程序自身。因此,我想了解如何将变量传递给父批处理文件。我可以在批处理调用另一个批处理时执行此操作,但不能在批处理文件调用 jar 文件时执行此操作,实习生创建批处理文件,执行它并退出。这是我的代码。

    import java.awt.Window;
    import java.io.BufferedWriter;
    import java.io.File;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.UnsupportedEncodingException;
    import java.net.URLDecoder;
    import java.security.InvalidAlgorithmParameterException;
    import java.security.InvalidKeyException;

    import javax.crypto.BadPaddingException;
    import javax.crypto.IllegalBlockSizeException;
    import javax.crypto.ShortBufferException;

    import junit.framework.Test;

    public class main 
    {
        private static byte[] KeyBytes = {0,0,0,0,0,0,0,0};
        private static byte[] ivBytes = {0,0,0,0,0,0,0,0};

        public static void main(String[] args) throws InvalidKeyException, InvalidAlgorithmParameterException, IllegalBlockSizeException, ShortBufferException, BadPaddingException, IOException, ClassNotFoundException, InterruptedException
        {   
            ObjectCrypter EncStr = new ObjectCrypter(KeyBytes,ivBytes);
            if(args.length == 2 )
            {
                if (args[0].equals("-E")|args[0].equals("-e"))
                {
                    byte[] tbyte = EncStr.encrypt(args[1]);
                    String test = byteToString(tbyte); 
                    System.out.println(test);
                }
                else if (args[0].equals("-D")|args[0].equals("-d"))
                {
                    byte[] t = stringToByte(args[1]);
                    writeBat("SET HypPWD=" +String.valueOf(EncStr.decrypt(t)));
                    //System.out.println("cmd /C " + getPath() + "tmpPwd.bat");
                    Process proc = Runtime.getRuntime().exec("cmd /C start tmpPwd.bat");
                    proc
                    proc.waitFor();
                }
            }
            else
            {
                System.out.println("Wrong Argument set please revise input");
                System.exit(0);
            }
        }
        private static String getPath() throws UnsupportedEncodingException 
        {
//....
        }
        public static String byteToString(byte[] b) 
        {
//....
        }
        public static byte[] stringToByte(String s)
        {
//....
        }
        public static void writeBat(String txt)
          {
              try
              {
                  FileWriter fstream = new FileWriter("tmpPwd.bat");
                  BufferedWriter out = new BufferedWriter(fstream);
                  out.write("@ECHO OFF");
                  out.newLine();
                  out.write(txt);
                  out.newLine();
                  out.write("EXIT");
                  out.newLine();
                  out.write("DEL tmpPwd.bat");
                  out.close();
              }
              catch (Exception e)
              {
                  System.err.println("Error: " + e.getMessage());
              }
          }
4

0 回答 0