jQuery in Action, 2nd edition*
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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
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
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

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://aspose.com/file-tools
 
subject: how to accomplish variable interpolation in a string
 
Similar Threads
Problem in executing shell script using JSP
How to call Oracle sqlldr in Java
problem reading output of a subprocess
How to call a Perl program in Servlet?
Problem with running a shell script from the JSP