Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Launching files programatically

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import java.util.*;
public class GoodWindowsExec
{
public static void main(String args[])
{
Vector v = new Vector();
v.add("D:\\file1.java");
v.add("D:\\file2.java");
v.add("D:\\file3.java");

//v.add("D:\\file1.java&D:\\file2.java");


for(int i=0;i<v.size();i++)
{
try
{
String path = v.elementAt(i).toString();
String osName = System.getProperty("os.name" );
String[] cmd = new String[3];

cmd[0] = "cmd.exe" ;
cmd[1] = "/C" ;
cmd[2] = path;


Runtime rt = Runtime.getRuntime();
System.out.println("Executing : " + cmd[0] + " "
+ cmd[1]+ " " + cmd[2]);
Process proc = rt.exec(cmd);
}
catch (Throwable t)
{
t.printStackTrace();
}
}
}
}


I tried to execute above program.
The default editor for java files is set to TextPad.
But when i run the program then it launched 3 different instances of textpad.

If i used '&' seperated filenames(Example : pah ="D:\\file1.java&D:\\file2.java") then it opens the next file when i close the first file.

What i want to do is :
1. Only one instance of textpad should open all the files.
2. If textPad is already lauched then on executing the program new instance of textpad should not be lauched .The files should be opened in the existing instance.

Any help in this would be of great help to me.

Thanks & Regards,
Veda
 
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
TextPad has an option to allow this which prevents it opening every time you open a file associated with it.

In TextPad, click on Configure --> Preferences, then make sure "Allow multiple files on the command line" is selected.

Steve
 
veda patil
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the reply.
Now i can open the files in same instance on the editor.

I have one more problem in this respect :
The scenario is i open a html file programatically.
Now i do not close the earlier launched browser and run the program again.
This lauches another insatnce of browser.
Do you have any idea about how to open an html file in same instance of the browser.

Thanks & Regards,
Veda
 
Steve McCann
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry Veda - I don't have any ideas how to do that.

Steve
 
Rancher
Posts: 5008
38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you do what you want manually from a command prompt?
IE does the browser support it?
Does it depend on the application or the OS whether it uses an existing invocation or starts a new one?
 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Use JDICs org.jdesktop.jdic.desktop.Desktop.open(java.io.File) and Desktop.browse(java.net.URL url) are what you are after.
 
This guy is skipping without a rope. At least, that's what this tiny ad said:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic