Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Invoking Script in Java.

Posted on 1998-06-26
1
Medium Priority
?
279 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 5

Accepted Solution

by:
fontaine earned 150 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

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 …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
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:
Suggested Courses

719 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