• Post Reply Bookmark Topic Watch Topic
  • New Topic

Launching files programatically  RSS feed

 
veda patil
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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
 
Steve McCann
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
Sorry Veda - I don't have any ideas how to do that.

Steve
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • 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?
 
Michael Lloyd Lee
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!