madhesh raj

Ranch Hand
+ Follow
since Nov 28, 2000
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by madhesh raj

Hi,
When i execute a external program i know that it starts a new process. I want to know whether the new process runs in the same JVM or a new JVM instance is started which exits when the process exits.
What is the concept here?
Thanks
Madhesh
22 years ago
Hi,
Here's an example. I would like to know whether it is possible to write to the Process OutputStream also so that the Process can get input from this stream
/* Program reads the output generated by another process */

import java.util.*;
import java.io.*;
public class ProcessRead
{
public static void main(String []args)
{

try
{
Runtime rtime = Runtime.getRuntime();
Process process=rtime.exec("java Hello"); // Hello is a prog to print Helloworld
InputStream inpt = process.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(inpt));
String check="";
while( (check = br.readLine()) != null )
{
System.out.println(check);
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
22 years ago
Hi
This is very much needed in my project. So, pls help me out.
Madhesh
22 years ago
Hi Thomas,

Thanks for the reply. The code worked. Could you please explain the code in simple terms.
Thanks
Madhesh
22 years ago
Hi,
I create a process by using Runtime.exec method
Supposing the process needs some keyboard input from user. Can i map the input to the process's OutputStream.
I tried reading the Process's output using the InputStream of the process and it works fine. How abt the other way?
A simple example i can think of is a Echo program which will demonstrate both the concepts. Can anyone give the code or clarify my doubt.
Thanks
Madhesh
22 years ago
Hi,
Does reading from the process's InputStream work the other way round also. That is, suppose the process is expecting some keyboard input from user then can i map it using the the process's OutputStream?
Pls give a sample code. It would be really useful
Madhesh
22 years ago
Hi Thomas,
You have misunderstood my question. All ur points are very much true and valid.
But my question was to get the class name itself from the string variable when there are a unknown number of classes. We may be able to do it using reflection, i am not sure. But, i don't want to use the reflection package
Regards
Madhesh
22 years ago
Hi,
Consider the classic case of a Javaeditor capable of compiling and running a Java program. It needs to select a class file at runtime and execute the same. We will get the classname as a string from the frontend. Since, there maybe any no. of classes, how do we invoke the correct method. It is needless to say that they cannot have a single abstract class as a common parent. How to go abt identifying the correct class from the string
Madhesh
22 years ago
Hi,
Your suggestion works only if we have a predefined set of classes against which we can compare.
But, consider the classic case of a Javaeditor capable of compiling and running a Java program. It needs to select a class file at runtime and execute the same. We will get the classname as a string from the frontend. Since, there maybe any no. of classes, how do we invoke the correct method. It is needless to say that they cannot have a single abstract class as a common parent
Madhesh
22 years ago
Hi,
Is there any Java equivalent for Function pointers in C/C++.
I know there is no pointer concept in Java. What i am looking at it is calling functions at runtime by using some variable. I will get the class name in a String variable at runtime only.
For further clarification pls see the code in my previous post.
Regards
Madhesh
22 years ago
Hi,
In my application, i get a class name during runtime in a String variable. Using this variable i want to invoke the main function. I have already tried using Class.forName(stringvar). But it doesn't work. Here is the code
public class RunExample
{
public static void main(String []args)
{
String prog = new String("Test");
//Test is the class file name in which main method prints Hello
Class obj = Class.forName(prog);
try
{
(obj.getName()).main(new String[0]);
}
catch(Exception e)
{
}
}
}

However, if i hardcode the class name like
Test.main(new String[0]) it works fine
22 years ago
Hi Frank,
Thanks for the suggestion. I could not get what the new String[0] does. Is it to pass the arguments to the called program? (in this case HelloWorld)?
IF not, Supposing i want to pass some arguments to the second program what do i need to do? Can i just form my own String array of arguments and pass it.
Regards
Madhesh
22 years ago
Hi,
I am developing a java editor like textpad. I am stuck at one point. My editor is similar to Textpad.
The editor gives a GUI for editing, compiling and running Java Programs. I am stuck at a point. When i try to run a program that recieves user input from within my editor, i want to open a new command window to recieve user input. This input must be available for the program. This is how TextPad does it.
How do i achieve it? Pls help
Madhesh
22 years ago