Solved

Invoking Script in Java.

Posted on 1998-06-26
1
264 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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

For customizing the look of your lightweight component and making it look opaque like it was made of plastic.  This tip assumes your component to be of rectangular shape and completely opaque.   (CODE)
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 will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now