Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

execute external program

 
kanika dua
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to execute an external program-
net2phone(Its a freeware to make PC to Phone calls) from a java program.
public class TestExec {
public static void main(String[] args) throws Exception {
Process p = Runtime.getRuntime().exec(
"\"C:/Program Files/Net2Phone CommCenter/CommCtr.exe\"");
p.waitFor();
}
}
I want to use something similar to sendKeys in VB to send the number to be dialed automatically via the script. Can somebody help me with this or if any other command is available in java to accomplish this-
Thanks
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
kaniks
Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however,
your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy.
Thanks again and we hope to see you around the ranch!!
 
Steve Deadsea
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
First, you are using exec() incorrectly. It does not parse a command line with spaces and quotes the way you are expecting it to. It thinks all quotes are literals and tokenizes only on spaces. You will want to tell it that your command is pre-parsed by using it like this:

I also don't know of any sendkeys function in Java. See if the program accepts command line arguments, as that would be the standard way of passing data to it. For example, something like:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic