Results 1 to 5 of 5

Thread: Java code to run batch file

  1. #1
    Join Date
    Mar 2010
    Posts
    191

    Java code to run batch file

    Hello,
    I need to make a java program to run a script (a batch) and I do not know where to begin. (The batch is to connect via ftp to a remote unix server and download files). Any help regarding this topic is appreciated. Thanks in advance.

  2. #2
    Join Date
    Nov 2009
    Posts
    335

    Re: Java code to run batch file

    Hello,
    Why run a bash script to execute ftp commands when you can do it directly in Java code, with good API? You can also do that with the protocol ssh. And if for a specific reason, you have to go through your bash file, then looks toward Runtime.exec (). I think you can use this method in your code. See, if this works in your code then let me know and also if it does not work then tell me.

  3. #3
    Join Date
    Nov 2009
    Posts
    330

    Re: Java code to run batch file

    Hello,
    Try this code, if it works well and good.
    Code:
    Runtime rntm = rntm.getRuntime();
    			 try {
    				rntm.exec(New String[] {C:\\some.bat "} );
    			} wrestling (IOException e1) {
    				e1.printStackTrace();
    			}
    I hope the above code will solve your problem.

  4. #4
    Join Date
    Nov 2009
    Posts
    446

    Re: Java code to run batch file

    Hello,
    Just have a look at the batch file, it should be something like this
    Code:
    @ Echo off
    : Start
    echo 1 : Menu1
    echo 2 : Menu2
    echo 3 : Menu3
    set / p chc = choose a number.
    if % chc% == not'' set chc =% chc: ~0,1%
    if % chc% ==1 goto Menu1
    if % chc% ==2 goto Menu2
    if % chc% ==3 goto Menu3
    echo% chc% nIs not good!
    goto top
    : Menu1
    echo Hello & goto: eof
    : Menu2
    echo Goodbye & goto: eof
    : Menu3
    Farewell & echo goto: eof

  5. #5
    Join Date
    Nov 2009
    Posts
    518

    Re: Java code to run batch file

    Hello,
    Take a look at the following code, it may help you.
    Code:
    import java.io.IOException;
    public class src {
    	
    	public src(){
    	Runtime rn = rn.getRuntime();
    	 try {
    		rn.exec(New String[] {D:\\some.bat "} );
    	} wrestling (IOException e1) {
    		e1.printStackTrace();
    	}
     
    }
    	public static void hand(String []args){
    		src = scNew src();
    System.out.println("Hello"):	
    	}
    }

Similar Threads

  1. Running a batch file from a remote machine in a VB code
    By Radhu in forum Software Development
    Replies: 1
    Last Post: 14-10-2011, 04:54 PM
  2. Replies: 1
    Last Post: 19-03-2011, 01:28 AM
  3. help me to understand java code (calendar java code) ?
    By so0oma in forum Software Development
    Replies: 2
    Last Post: 10-01-2011, 12:01 AM
  4. A Simple File and Folder renaming batch code : RenameR
    By Rudra.J in forum Tips & Tweaks
    Replies: 2
    Last Post: 05-03-2009, 02:59 PM
  5. Exit code from a batch file?
    By Bhairav in forum Operating Systems
    Replies: 3
    Last Post: 17-02-2009, 05:38 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,751,425,639.25054 seconds with 16 queries