The Artima Developer Community
Sponsored Link

Java Answers Forum
help with passing a unix script varible to a java program

1 reply on 1 page. Most recent reply: Jun 26, 2002 6:06 PM by Matt Gerrans

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Tanveer Hossain

Posts: 1
Nickname: thossain
Registered: Jun, 2002

help with passing a unix script varible to a java program Posted: Jun 26, 2002 2:30 PM
Reply to this message Reply
Advertisement
i have a unix shell script that contains:
#! /bin/ksh

#loading the modules
module load msjava/jdk/1.2.2

java TestProg &
PID=$!

java NetVeryCool
java AlertNetCool
======================================
and my java program is:
import java.io.*;

public class AlertNetCool {

public static void main(String args[]) {

String s = null;

try {

// run the Unix command

Process p = Runtime.getRuntime().exec("ps -ef | grep $PID | grep -v grep");

BufferedReader stdInput = new BufferedReader(new
InputStreamReader(p.getInputStream()));

BufferedReader stdError = new BufferedReader(new
InputStreamReader(p.getErrorStream()));


// store the output from the command in
// a string and if null call netcool

System.out.println("Here is the standard output of the command:\n");
while ((s = stdInput.readLine()) != null) {
System.out.println(s);
}


System.out.println("Here is the standard error of the command (if any):\n");
while ((s = stdError.readLine()) != null) {
System.out.println(s);
}

System.exit(0);
}
catch (IOException e) {
System.out.println("exception happened - here's what it is: ");
e.printStackTrace();
System.exit(-1);
}
}
}
===================
question: how do i pass in $PID in my java program's Process p


Matt Gerrans

Posts: 1153
Nickname: matt
Registered: Feb, 2002

Re: help with passing a unix script varible to a java program Posted: Jun 26, 2002 6:06 PM
Reply to this message Reply
Use the -D command option of java to pass the variable into the program, then use System.getProperties() inside the program to get the value from the Properties object returned.

Flat View: This topic has 1 reply on 1 page
Topic: Problems with Parallelport Mode (Java Comm API) Previous Topic   Next Topic Topic: Writing a Unicode RTF text to a text file.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use