Link to home
Start Free TrialLog in
Avatar of mkhan900
mkhan900

asked on

Java combine command line programs.

I found the code below to solve my problem with a command line program. But since I am very new to java I don't understand how to incorporate this code along with mine. Can some one plz help me do this.
Following is the link to the code which I am trying to incorporate with my program
http://www.javalobby.org/java/forums/t53333.html

This needs to be incorporated with the above code

import java.io.*;
import java.lang.*;
public class enCryptFiles
{
      public static void main(String args[]) throws Exception
      {
         String Fname = new String();
          String[] filenames;
          File f = new File(args[0]);
          filenames = f.list();
          for(int i=0; i< filenames.length; i++)
        {                
           String[] command = new String[] { "cmd","/c","start","filecrypt ", "--encrypt "+ filenames[i] + " --user ", "PublicKey"};
         for (int t=0; t<command.length; t++)
               {Fname = Fname+" "+command[t];}  
               System.out.println(Fname);
          Process p = Runtime.getRuntime().exec(Fname);
          Fname = null;
  } }}    

Thanks
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

There's lots of code at that link. What you really seem to mean is that you want your original code fixed(?)
ASKER CERTIFIED SOLUTION
Avatar of CEHJ
CEHJ
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mkhan900
mkhan900

ASKER

There was very small error in my code. To find this error I thought of using the code from the link.
But I found the error.

In the loop I was only using the file name where as the Command Line program (like every program) required the absolute path along with the filename and it worked.

Thanks for your response Cehj
:-)

Does that code work properly now?
Yes it does.

Thanks for the help