Opening a new browser using Runtime.getRuntime().exec(cmd); under windows

Can Runtime.getRuntime().exec(cmd); open a URL in to a new browser in wondows OS or ...can we force it to any specific browser insted on OS's default browser...
It does open a new bowser under MAC but not under windows..
cmd = "'rundll32 url.dll,FileProtocolHandler"+URL (windows)
Thanks

public class WindowsProcess
     public static void main(String[] args)
          throws Exception
          String[] cmd = new String[3];
          cmd[0] = "cmd.exe";
          cmd[1] = "/C";
          cmd[2] = "start";
          Process process = Runtime.getRuntime().exec( cmd );
          process = Runtime.getRuntime().exec( cmd );
}When you run the above code you should get two open dos windows.
Now just just enter some html filename and hit enter in each window. IE should start up separately in each window.
Thats also what should happen if you specify the html file as the fourth parameter. A new process should be created and two separate windows should open with a browser in each.

Similar Messages

  • Opening a new browser using Runtime.exec()...

    I am trying to open a new IE browser window (from Windows) using Runtime.exec( ) command. The problem is that it uses the existing browser window instead of opening a new window. (opens a new window only if there isn't any other browser window)
    Here is the snippet of code that I am using to do this:
    String WIN_PATH = "rundll32";
    String WIN_FLAG = "url.dll,FileProtocolHandler";
    String url = "http://www.cnn.com";
    String cmd = WIN_PATH + " " + WIN_FLAG + " " + url;
    Process p = Runtime.getRuntime().exec(cmd);
    Thanks in advance.
    -Kishore

    >
    opening browser window seems to be easy task, >Even easier with [Desktop.browse(URI)|http://java.sun.com/javase/6/docs/api/java/awt/Desktop.html#browse(java.net.URI)].
    >
    ..can someone help me with closing browser window from java?>Which browser window?
    If you're app. opens a page that you control, it can be done from the web page. See [Have a Java button close the browser window|http://www.rgagnon.com/javadetails/java-0282.html] or the JS based [Close the browser|http://www.rgagnon.com/jsdetails/js-0079.html].
    If you do not control the page, don't close it - the user knows where the little 'x' button is.
    As an aside, despite being opposite ends of the one question, I do not consider this question to be 'part' of the current thread. I think you would have been better off starting a dedicated thread and explaining more fully what the use case is (and adding lots of Dukes).

  • Runtime.getRuntime().exec("cmd /c start file\\"+"My file.txt" ) Not work

    Hello
    i have a problem I use:
    Runtime.getRuntime().exec("cmd /c start file\\"+"My file.txt");
    to open "my file.txt" And I have error System Windows don't open file file\My becaus file My don't exist When I rename file to "Myfile.txt" and use:
    Runtime.getRuntime().exec("cmd /c start file\\"+"Myfile.txt");
    It's work great. My problem is when my file have space in name or other [ ], etc symbol. How fix this problem?
    Thenks to help:)

    Try using the verson where you specify the parameters in an array as this example shows:
    http://forum.java.sun.com/thread.jspa?forumID=31&threadID=635363
    Note: you may need to enclose the file name in quotes

  • How to use Runtime.getRuntime().exec() in JSP? is it works in JSP or not

    Hi to all,
    i want run a .exe file from JSP file. In java i am able do this, using Runtime.getRuntime().exec().
    but same thing, when i trying with JSP it is not working?
    plz let me is there any other ways to do it..

    It depends, usually (ie in an J2EE container) you're not allowed to access files or the runtime environment, by definition. What do you wan't to achieve with the exe?
    --olaf                                                                                                                                                                                                                                                                                                                                                           

  • Is there any way to run without using Runtime.getRuntime().exec()

    I am looking for a way to get my program to fun files on my system without using
    Runtime.getRuntime().exec() because it's causing me nothing but problems, is there any other way to do it without using this command?

    Can't think of an easier way (JNI, etc.).
    If you have not read the following article you really should, it might clear up a lot of your problems with exec():
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Swign application and Runtime.getRuntime().exec(cmd)

    i want to use this program in a swing application, when i press the button it will execute this comand,?? is possible?
    String[] cmd = {"pwd","ls"};
    try {
    Process ls = Runtime.getRuntime().exec(cmd);
    BufferedReader input1 = new BufferedReader(new InputStreamReader(ls.getInputStream()));
    String str = input1.readLine();
    /* Keep looping until we have read all of the output */
    while(str != null) {
    System.out.println(str);
    str = input1.readLine();
    } catch (java.io.IOException el) {
    System.err.println(el);
    import javax.swing.*;
    import java.awt.event.*;
    public class Main{
    JFrame frame;
    public static void main(String[] args){
    Main db = new Main();
    public Main(){
    frame = new JFrame("Show Message Dialog");
    JButton button = new JButton("Click Me");
    button.addActionListener(new MyAction());
    frame.add(button);
    frame.setSize(400, 400);
    frame.setVisible(true);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    public class MyAction implements ActionListener{
    public void actionPerformed(ActionEvent e){
    JOptionPane.showMessageDialog(frame,"hello");
    }

    its pretty hard to read without code tags,
    if your questions is can i use this code in my new swing applications when i press a button
    sure you can you need to make your new program with actionlisterners, your button will then wait until you click on it,
    then you will call your old method when the button is clicked
    I think that what you want sorry if i got the wrong end of the stick

  • Runtime.getRuntime().exec works on windows failed on linux!

    Hi,
    I'm trying to execute a linux command from java 1.4.2 using Runtime.getRuntime().exec(). The linux command produces output and write to a file in my home dir. The command runs interactively in the shell and also run on windows.
    The command is actually a mozilla pk12util. My java code to run this pk12util works on windows, but not on linux (fedora). When I print out the command I'm trying to run in java, I can run it interactively in bash shell.
    Method below is where the problem seems to be:
    public void writeCert() {
    // Declaring variables
    System.out.println("Entering writeCert method");
    String command = null;
    certFile = new File(credFileName);
    // building the command for either Linux or Windows
    if (System.getProperty("os.name").equals("Linux")) {
    command = linuxPathPrefix + File.separator + "pk12util -o "
    + credFileName + " -n \"" + nickName + "\" -d "
    + dbDirectory + " -K " + slotpw + " -w " + slotpw + " -W "
    + pk12pw;
    System.out.println("System type is linux.");
    System.out.println("Command is: " + command);
    if (System.getProperty("os.name").indexOf("Windows") != -1) {
    // command = pk12utilLoc + File.separator + "pk12util -o
    // "+credFileName+" -n "\"+nickname+\"" -d \""+dbDirectory+"\" -K
    // "+pk12pw+" -w "+pk12pw+" -W "+pk12pw;
    command = pk12utilLoc + File.separator + "pk12util.exe -o "
    + credFileName + " -n \"" + nickName + "\" -d "
    + dbDirectory + " -K " + slotpw + " -w " + slotpw + " -W "
    + pk12pw;
    System.out.println("System type is windows.");
    System.out.println("Command is: " + command);
    // If the system is neither Linux or Windows, throw exception
    if (command == null) {
    System.out.println("command equals null");
    try {
    throw new Exception("Can't identify OS");
    } catch (Exception e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    // Having built the command, running it with Runtime.exec
    File f = new File(credFileName);
    // setting up process, getting readers and writers
    Process extraction = null;
    BufferedOutputStream writeCred = null;
    // executing command - note -o option does not create output
    // file, or write anything to it, for Linux
    try {
    extraction = Runtime.getRuntime().exec(command);
    } catch (IOException e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    // Dealing with the the output of the command; think -o
    // option in command should just write the credential but dealing with output anyway
    BufferedWriter CredentialOut = null;
    OutputStream line;
    try {
    CredentialOut = new BufferedWriter (
    new OutputStreamWriter(
    new FileOutputStream(credFileName)));
    catch (FileNotFoundException e) {
    System.out.println(e.getMessage());
    e.printStackTrace();
    // writing out the output; currently having problems because I am trying to run
    }

    My error is due to the nickname "-n <nickname" parameter error. I think the problem is having a double quotes around my nickname, but if I take out the double quotes around my nickname "Jana Test's ID" won't work either because there are spaces between the String. Error below:
    Command is: /usr/bin/pk12util -o jtest.p12 -n "Jana Test's Development ID" -d /home/jnguyen/.mozilla/firefox/zdpsq44v.default -K test123 -w test123 -W test123
    Read from standard outputStreamjava.io.PrintStream@19821f
    Read from error stream: "pk12util: find user certs from nickname failed: security library: bad database."
    null
    java.lang.NullPointerException
    at ExtractCert.writeCert(ExtractCert.java:260)
    at ExtractCert.main(ExtractCert.java:302)
    Code is:
    private String nickName = null;
    private void setNickname(String nicknameIn) {
    nickName = nicknameIn;
    // building the command for either Linux or Windows
    if (System.getProperty("os.name").equals("Linux")) {
    command = linuxPathPrefix + File.separator + "pk12util -o " + credFileName + " -n \"" + nickName + "\" -d " + dbDirectory + " -K " + slotpw + " -w " + slotpw + " -W " + pk12pw;
    System.out.println("System type is linux.");
    System.out.println("Command is: " + command);
    extraction = Runtime.getRuntime().exec(command);
    BufferedReader br = new BufferedReader(
    new
    InputStreamReader(extraction.getErrorStream()));
    PrintStream p = new PrintStream(extraction.getOutputStream());
    System.out.println("Read from standard outputStream" + p);

  • Runtime.getRuntime().exec(cmd) not working

    I have created binary scrip to parse file from one format to another format and the file parser is available on Linux path and working fine when calling from command prompt but while calling this program from jsf or any any java form bean it adds some special charaters with program and throws IOException as belows
    calling command
    String[]     cmd={"delimiter",inputFile.toString(),outputFile.toString()};
    Process     p=Runtime.getRuntime().exec(cmd);
    it gives following error.
    java.io.IOException: delimiter@! : not found
    while calling this from jaav main application working fine.
    any suggestion would be appriciated.
    Cheers,
    dharmendra

    Thanks.
    I printed out whatever values are being passed and it is printing the right values on console and in log file and I also tried this command in stand alone application program an working fine. but when I call it from jsf form bean it adds ^@ at the end of first parameter and says ;
    IOException : delimiter^@ : not found
    i actually created the same copy as delimiter^@ and put it in same path directory with 777 mode.
    and now its working fine. but I did not know the reason why it change the name of first argument.
    Thanks,

  • How to execute an application in Solaris using Runtime.getRuntime.exec() ?

    I am currently doing a project which requires the execution of Solaris applications through the use of Java Servlet with this Runtime method - Runtime.getRuntime.exec()
    This means that if the client PC tries to access the servlet in the server PC, an application is supposed to be executed and launched on the server PC itself. Actually, the servlet part is not an issue as the main problem is the executing of applications in different platforms which is a big headache.
    When I tried running this program on a Windows 2000 machine, it works perfectly fine. However, when I tried it on a Solaris machine, nothing happens. And I mean nothing... no errors, no nothing. I really don't know what's wrong.
    Here's the code.
    public void doPost(HttpServletRequest request, HttpServletResponse response)
         throws ServletException, IOException
         response.setContentType("text/html");
         PrintWriter out = response.getWriter();
              Process process;                                                       Runtime runtime = Runtime.getRuntime();
              String com= "sh /opt/home/acrobat/";
              String program = request.getParameter("program");
              try
                        process = runtime.exec(com);
              catch (Exception e)
                   out.println(e);
    It works under Windows when com = "c:\winnt\system32\notepad.exe"
    When under Solaris, I have tried everything possible. For example, the launching of the application acrobat.
    com = "/opt/home/acrobat"
    com = "sh /opt/home/acrobat"I have also tried reading in the process and then printing it out. It doesn't work either. It only works when excuting commands like 'ls'
    BufferedReader read = new BufferedReader(new InputStreamReader(process.getInputStream()));Why is it such a breeze to execute prgrams under Windows while there are so many problems under Solaris.
    Can some experts please please PLEASE point out the errors and give me some advice and help to make this program work under Solaris! Please... I really need to do this!!
    My email address - [email protected]
    I appreciate it.
    By the way, I'm coding and compiling in a Windows 2000 machine before ftp'ing the .class file to the Solaris server machine to run.

    it is possible that you are trying to run a program that is going to display a window on an X server, but you have not specified a display. You specifiy a display by setting the DISPLAY environment variable eg.
    setenv DISPLAY 10.0.0.1:0
    To check that runtime.exec is working you should try to run a program that does not reqire access to an X Server. Try something like
    cmd = "sh -c 'ls -l > ~/testlist.lst'";
    alternatively try this
    cmd = "sh -c 'export DISPLAY=127.0.0.1:0;xterm '"
    you will also need to permit access to the X server using the xhost + command

  • Running curl command from a java program using Runtime.getRuntime.exec

    for some reason my curl command does not run when I run it from within my java program and errors out with "https protocol not supported". This same curl command however runs fine from any directory on my red hat linux system.
    To debug the problem, I printed my curl command from the java program before calling Runtime.getRuntime.exec command and then used this o/p to run from the command line and it runs fine.
    I am not using libcurl or anything else, I am running a simple curl command as a command line utility from inside a Java program.
    Any ideas on why this might be happening?

    thanks a lot for your response. The reason why I am using curl is because I need to use certificates and keys to gain access to the internal server. So I use curl "<url> --cert <path to the certificate>" --key "<path to the key>". If you don't mid could you please tell me which version of curl you are using.
    I am using 7.15 in my system.
    Below is the code which errors out.
    public int execCurlCmd(String command)
              String s = null;
              try {
                  // run the Unix "ps -ef" command
                     Process p = Runtime.getRuntime().exec(command);
                     BufferedReader stdInput = new BufferedReader(new
                          InputStreamReader(p.getInputStream()));
                     BufferedReader stdError = new BufferedReader(new
                          InputStreamReader(p.getErrorStream()));
                     // read the output from the command
                     System.out.println("Here is the standard output of the command:\n");
                     while ((s = stdInput.readLine()) != null) {
                         System.out.println(s);
                     // read any errors from the attempted command
                     System.out.println("Here is the standard error of the command (if any):\n");
                     while ((s = stdError.readLine()) != null) {
                         System.out.println(s);
                     return(0);
                 catch (IOException e) {
                     System.out.println("exception happened - here's what I know: ");
                     e.printStackTrace();
                     return(-1);
         }

  • Using Runtime.getRuntime().exec(DOS Program) with Windows 2000.

    I am trying to spawn a DOS Program from within Java.
    On Win95/98/ME, I use
    Process     p = Runtime.getRuntime().exec("START /w command.com con /c myDOSProgram.exe");
    This works on these platforms. On Win 2000, I use
    Process     p = Runtime.getRuntime().exec("START /w cmd.exe con /c myDOSProgram.exe");
    It does not work at all.
    I have tried all combinations of using START, cmd.exe, con /c, etc.
    I can spawn a Windows App using
    Process     p = Runtime.getRuntime().exec("windows.exe");
    And it works fine.
    What does it take to spawn a DOS program from Java on the Windows 2000 op sys?

    Hi. I recently wrote a java GUI that calls a DOS program with mixed success. Here's the code I used to make the call:String osName = System.getProperty("os.name" );
    String[] cmd = new String[4];
    if( osName.equals( "Windows 2000" ) || osName.equals( "Windows NT" ) )
         cmd[0] = "cmd.exe";
         cmd[1] = "/C" ;
         cmd[2] = "VBDoc.exe";
         cmd[3] = fileName;
    else if( osName.equals( "Windows 95" ) || osName.equals( "Windows 98" ) )
         cmd[0] = "command.com" ;
         cmd[1] = "/C" ;
         cmd[2] = "VBDoc.exe";
         cmd[3] = fileName;
    else
         System.out.println(osName);
    Process proc = runtime.exec(cmd);Check out this article, it gives a good explanation of how to use the exec() call:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Hope this helps!

  • Runtime.getRuntime.exec(cmd) - 'out of space'

    And helpful suggestions from the Java / AIX boffins out there would be appreciated.
    System: AIX 4.3 jdk 1.3.1
    Briefly, I am attempting to invoke the ibm 'c' compiler from within a java program.
    The command:-
    p = Runtime.getRuntime.exec("/usr/ibmcxx/bin/cc test.c")
    returns the os error 'mmap failed: Not enough space'
    other commands that do work:-
    p = Runtime.getRuntime.exec("ls -l")
    return successfully without error
    p = Runtime.getRuntime.exec("/usr/ibmcxx/bin/cc Notfound.c")
    raises the error '/usr/ibmcxx/bin/cc 1501-288 input file NotFound.c not found' - as expected.
    Additionally:-
    I have tried invoking the program with the -msnnM & -mxnnM flags set to large values.
    /usr/ibmcxx/bin/cc test.c : works happily from the command line.
    cheers
    John.

    Thanks but not made any difference.
    keep those ideas coming!
    Does any body 'real' understand how the getRuntime() interacts with the underlying OS? I assume that the "mmap failed" is coming from the compiler rather then the JVM. But does it throw this error only when run through the JVM ?
    John.

  • Opening new browser using button

    Hi there:
    I am trying to insert a link to a webpage which I would like
    to have open in a new browser. I selected 'Open URL or file',
    entered the URL [complete with http] and then selected 'New' from
    the drop down list. When I run the file [I have done this locally
    from my hard drive and am wondering if that may be the issue] and
    click on the button nothing happens.
    As a test I changed the URL to be the location for file and
    it opens the file fine. Do I need to wait until the video is
    implemented on the web before the link will work?
    Thanks!

    public class WindowsProcess
         public static void main(String[] args)
              throws Exception
              String[] cmd = new String[3];
              cmd[0] = "cmd.exe";
              cmd[1] = "/C";
              cmd[2] = "start";
              Process process = Runtime.getRuntime().exec( cmd );
              process = Runtime.getRuntime().exec( cmd );
    }When you run the above code you should get two open dos windows.
    Now just just enter some html filename and hit enter in each window. IE should start up separately in each window.
    Thats also what should happen if you specify the html file as the fourth parameter. A new process should be created and two separate windows should open with a browser in each.

  • Using Process Runtime.getRuntime().exec

    http://im1.shutterfly.com/procserv/47b4d633b3127cceb46774c84ee80000001610
    Here is a URL to a part of the current process I need to run. Actually there are 4 steps that preceed these but they are ran in order and must be done before these (that part is easy). Sorry it kinda chopped off the left side a little bit.
    My question is, can I do this entirely using Runtime.getRuntime().exec() commands or do I need to involve multi threading. The reason I am asking is because P13 cannot run until P8 and P9 completes, but that shouldn't stop the rest of the program from running.
    If I have something like
    Process P4 = Runtime.getRuntime().exec(P4);
    Process P5 = Runtime.getRuntime().exec(P2);
    // Some handling for the streams of these processes goes here
    P4.waitFor();
    P2.waitFor();
    if(P2.exitValue() != 0){
    Process P5 = Runtime.getRuntime().exec(P5);
    Process P6 = Runtime.getRuntime().exec(P6);
    // Some handling for the streams of these processes goes here
    Does that mean the whole program will stop and wait until P4 is done before even checking for P2? If P2 is finished would the program continue and run P5 and P6 even if P4 is still running or will it wait for P4 to complete also. P4 has nothing to do with P2?
    Also any advice ???

    P4 and P2 will both be running in parallel (or as much as your OS and hardware allows them to be). As soon as both are done, and regardless of which finishes first, whatever follows P2.waitFor() will execute.
    If you have multiple groups of processes, where the processes within a group must execute sequentially, but the groups themselves can run independently of each other, then you'll need to either use Java's threads, or wrap each group of sequential processes in a shell script or batch file the executes that group sequentially.
    If there are complex dependencies among the groups--that is, multiple groups must wait on the same process, or one group must wait for multiple other groups, then it might be easier to control the concurrency in Java.

  • Access denied when Runtime.getRuntime().exec

    I have an applet that opens a JFrame.
    In the JFrame I have a JButton, when I click the button I want a browser to open with a specific website.
    This doesn't work.
    When I look in the cmd-prompt it says:
    "java.security.AccessControlException: access denied (java.io.FilePermission C:\Program execute)"
    What have I done wrong? Do I have to change the security settings? Where do I that?
    class KnappListener implements ActionListener {
    public void actionPerformed(ActionEvent e) {
    frame2 = new JFrame(e.getActionCommand());
    frame2.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {System.exit(0);}});
    String website = new String("http://www.microsoft.com");
    try {
    Runtime.getRuntime().exec("C:\\Program Files\\Internet Explorer\\IEXPLORE.exe"+website);
    //Runtime.getRuntime().exec("cmd/C"+"start.exe"+website);
    catch (IOException io) {}
    }

    it doesn't matter which class your program extends. if your program is an applet (running in a browser) it is not permitted to use Runtime.getRuntime().exec(). If your program is an application, it is allowed to do so.
    I think there is a way for applets to get the permission through a policy, but I don't know how to do this.

Maybe you are looking for

  • Problem with printer on airport that was working 3 weeks ago.

    Hello I have an airport extreme and have connected to it an epson sp rx700. 3 weeks ago when I last used it, it was working fine. I have a macbook too which I print wirelessly through the extreme too. Yesterday I tried printing on my imac and it reco

  • Recording from a MIDI device

    Hello, Is it possible to record from a MIDI device? I connected my keyboard via an M-Audio USB UNO interface. I used MIDI-OX to confirm that my Windows XP PC was able to input and output a MIDI signal. But I do not see a MIDI input option in Soundboo

  • Is it possible to use smartseek functionalities without FMS(flash media server)??

    Hi,     Is it possible to use smart seek functionalities to play files local files without using flash media server(FMS).     I am currently using videoDisplay components but can switch to netStream component if it is possible without FMS.     As I h

  • How can I synchronize IPTC Extension metadata in LR 5?

    All - The Copy and Synchronize Metada interfaces to LR 5 shows IPTC Extension (IPTC Image fields and others) metadata, however when I use these functions this information is not included. Is this a limitation or a bug? How can I get this to work? Kin

  • When buying app error invalid address

    When buying app error invalid address