Two Laptop Bag
The moose likes Java in General and the fly likes how to accomplish variable interpolation in a string Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "how to accomplish variable interpolation in a string" Watch "how to accomplish variable interpolation in a string" New topic
Author

how to accomplish variable interpolation in a string

abhinav sinha
Greenhorn

Joined: Nov 29, 2007
Posts: 22
Hi,

I am not able to interpolate a variable.I am new to Java programming so I am do not know about it.Here is a part of sample code which I am using -

-----------------------------------------------------------------
<code>
public void itemStateChanged(java.awt.event.ItemEvent e) {
if (e.getStateChange() == e.SELECTED) {
String abh=(String)e.getItem();
System.out.println("the script chosen by abhinav is "+ abh);
File f = new File("scripts\\"+e.getItem());
if (! f.exists())
{
JOptionPane.showMessageDialog(null,e.getItem()+" does not exists","LAB DIALER ERROR", 1);
}
String cmd = "perl scripts/abh";
Process p=null;
p=Runtime.getRuntime().exec(cmd);

<\code>

The above program is not able to run the perl script because it is not able to interpolate the value of String abh in the String cmd.Please tell me how to do it.
Jesper de Jong
Java Cowboy
Bartender

Joined: Aug 16, 2005
Posts: 12911
    
    3

I don't know what you mean by "interpolate". Do you mean "concatenate"? I guess you'd want to do this:

String cmd = "perl scripts/" + abh;


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: how to accomplish variable interpolation in a string
 
Similar Threads
How to call a Perl program in Servlet?
Problem in executing shell script using JSP..Code is provided
problem reading output of a subprocess
Problem with running a shell script from the JSP
How to call Oracle sqlldr in Java