title: Passing a string in java into batch file for some other purposes
body: <p>I am currently finding ways to pass a string in java to a batch file where several commands will be running based on it.</p>
  
  <p>For example..</p>
  
  <pre><code>JFileChooser chooser = new JFileChooser();
      JButton btnSelect = new JButton("SELECT");
      btnSelect.addActionListener(new ActionListener() 
      {
          public void actionPerformed(ActionEvent args) 
          {
  
              //chooser.setMultiSelectionEnabled(true); //enable multiple selection of files
              int i = chooser.showOpenDialog(null);
  
              if (i == chooser.APPROVE_OPTION) 
              {
                  textField.setText(chooser.getSelectedFile().getAbsolutePath());
              }
  
              //works. able to output file path.
              //System.out.println(chooser.getSelectedFile().getAbsolutePath());
          }
      });
  //when start button is selected
      btnStart.addActionListener(new ActionListener()
      {
          public void actionPerformed(ActionEvent args)
          {
              // image info code
              try
              {   
                  //System.out.println(chooser.getSelectedFile().getAbsolutePath());
                  //create new process
                  String command = "cmd /c start /wait "+DetectDrive+"\\imageinfo.bat";
                  Process p = Runtime.getRuntime().exec(command);
  
                  //cause this process to stop until process p is terminated
                  p.waitFor();
              } 
              catch (IOException | InterruptedException e1)
              {
                  e1.printStackTrace();
              }
          }
      }
  </code></pre>
  
  <p>So this is part of my java coding. But what I want is that when the user uses the "select" option to choose a file, this file path is <code>System.out.println(chooser.getSelectedFile().getAbsolutePath());</code>.</p>
  
  <p>How can I pass this parameter to a batch file for other uses? Because my batch file will need the filepath chose by the user.</p>
  
  <p>I heard there's a way but I do not know how.. I tried researching but didn't seem to work. Any help will be greatly appreciated!!!</p>
  
  <p><strong>EDITED</strong></p>
  
  <p>I have written this to my java coding:</p>
  
  <pre><code>String filePath = chooser.getSelectedFile().getAbsolutePath();
  //create new process
  String command = "cmd /c start /wait "+DetectDrive+"\\BatchFiles\\imageinfo.bat";
  Process p = Runtime.getRuntime().exec(new String[]{command,"\""+filePath+"\""});
  p.waitFor();
  </code></pre>
  
  <p>When a user selects a file (e.g. E:\jooo.txt), the <code>filePath</code> is able to store that file path.
  But when I run it, there's seems something wrong with the <code>Process p = ...</code></p>
  
  <p>And I do not know what to write to my batch file so that the file path that the user has selected will be shown in the batch file. </p>
  
  <p>For example (<strong>In my batch file</strong>):</p>
  
  <pre><code>echo %filePath%
  </code></pre>
  
  <p>It doesn't seems to work. How should I code in the batch file so that it will show the file path that the user has selected in java?</p>
  
  <p>I'm new to this area so I need more help here. Any help will be greatly appreciated!</p>
  
  <p><strong>EDITED2</strong></p>
  
  <pre><code>java.io.IOException: Cannot run program "cmd /c start /wait E:\\imageinfo.bat": CreateProcess error=2, The system cannot find the file specified
      at java.lang.ProcessBuilder.start(Unknown Source)
      at java.lang.Runtime.exec(Unknown Source)
      at java.lang.Runtime.exec(Unknown Source)
      at Volatility$3.actionPerformed(Volatility.java:187)
      at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
      at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
      at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
      at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
      at java.awt.Component.processMouseEvent(Unknown Source)
      at javax.swing.JComponent.processMouseEvent(Unknown Source)
      ...
  </code></pre>
  
  <p>This is my error. I am trying to debug now.</p>