Solved

Invoking Script in Java.

Posted on 1998-06-26
1
267 Views
Last Modified: 2010-03-30
Can anyone just let me know how to invoke a shell script in a Java Code. Please provide me the syntax & sample for the same.
0
Comment
Question by:uramsi01
1 Comment
 
LVL 5

Accepted Solution

by:
fontaine earned 50 total points
ID: 1223801
Here is an example.

Shell script (test.sh):

#!/bin/sh
env > test.txt

Java prog:

import java.io.*;

public class ShellTest {

    public static void main(String args[]) throws IOException, InterruptedException {
         Runtime runtime = Runtime.getRuntime();
         String command = "test.sh"
         Process process = runtime.exec(command);
         process.waitFor(); // block until completion
         return;    
   }
}

Compile and run, "test.txt" appears with the environment in it.
0

Featured Post

ScreenConnect 6.0 Free Trial

Want empowering updates? You're in the right place! Discover new features in ScreenConnect 6.0, based on partner feedback, to keep you business operating smoothly and optimally (the way it should be). Explore all of the extras and enhancements for yourself!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question